By Peter Krauss


2013-02-24 22:13:54 8 Comments

This is not a duplicate question, I need only to decide if the better/fast/correct is to use attr or to use prop. The simplest and reliable way is checking into a list. A "list of element-name where the better is use prop(name) and/or a list where the better is use attr(name)".

PS: I am using jQuery 1.9+, and suppose that attr() is not a deprecated method.

Example of decisions (where the LIST have the answer):

  • is better get ID value by $(x).prop('id') or by $(x).attr('id')?
  • is better change title with $(x).prop('title','BLABLA') or with $(x).attr('title','BLABLA')?
  • can I use $(x).attr('selectedIndex')?
  • what property names have risk with "Cross-browser consistency"?
  • there are some case (with Microsoft-IE p.ex.) where $(x).attr('name') and $(x).prop('name') will return different things?

Perhaps a full list is not necessary, only a list of things that make some difference or risk for jQuery.

Edited after close: please click in the REOPEN link below to accept this edited question text.

2 comments

@Bergi 2013-02-24 22:40:45

Have a look at https://developer.mozilla.org/en-US/docs/DOM/element#Properties and also consider that many properties are only available on special types of elements.

@kaidez 2013-02-24 22:20:48

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

Related Questions

Sponsored Content

65 Answered Questions

[SOLVED] How to check whether a checkbox is checked in jQuery?

17 Answered Questions

[SOLVED] .prop() vs .attr()

31 Answered Questions

42 Answered Questions

[SOLVED] Is there an "exists" function for jQuery?

  • 2008-08-27 19:49:41
  • Jake McGraw
  • 729758 View
  • 2673 Score
  • 42 Answer
  • Tags:   javascript jquery

55 Answered Questions

[SOLVED] How do I check if an element is hidden in jQuery?

35 Answered Questions

[SOLVED] Add table row in jQuery

40 Answered Questions

[SOLVED] Setting "checked" for a checkbox with jQuery?

29 Answered Questions

[SOLVED] jQuery scroll to element

  • 2011-07-13 09:49:44
  • DiegoP.
  • 2367164 View
  • 2203 Score
  • 29 Answer
  • Tags:   javascript jquery

17 Answered Questions

[SOLVED] Disable/enable an input with jQuery?

Sponsored Content