JQuery attr vs. prop, is there a list of details?

This is not a duplicate question, I only need to decide whether to use / fast / correct to use attr or to use prop . The easiest and most reliable way is to check the list. "A list of element names where it is better to use prop(name) and / or a list of where it is better to use attr(name) ."

PS: I am using jQuery 1.9+, and suppose attr() not an obsolete method.

Example solutions (where LIST has the answer):

  • is it better to get the ID value on $(x).prop('id') or $(x).attr('id') ?
  • is it better to change the name with $(x).prop('title','BLABLA') or with $(x).attr('title','BLABLA') ?
  • Is it possible to use $(x).attr('selectedIndex') ?
  • Which properties have a risk with Cross Browser Context ?
  • Is there any case (with Microsoft-IE p.ex.) where $(x).attr('name') and $(x).prop('name') will return different things?



Perhaps a complete list is not needed, but only a list of things that may affect jQuery or its risk.

Edited after closing: click the REOPEN link below to accept this edited question text.

+4
javascript jquery attr prop
Feb 24 '13 at 22:13
source share
2 answers

They differ from browser to browser, but here is a list of IE ... http://msdn.microsoft.com/en-us/library/ie/hh773183(v=vs.85).aspx

+1
Feb 24 '13 at 22:20
source share

Take a look at https://developer.mozilla.org/en-US/docs/DOM/element#Properties and make sure that many properties are available only for special element types.

+1
Feb 24 '13 at 22:40
source share



All Articles