Answer Posted / chaitanya
attr(): Get the value of an attribute for the first element in the set of matched elements. Whereas,.prop(): (Introduced in jQuery 1.6) Get the value of a property for the first element in the set of matched elements.
Attributes carry additional information about an HTML element and come in name="value" pairs. Where Property is a representation of an attribute in the HTML DOM tree. once the browser parse your HTML code ,corresponding DOM node will be created which is an object thus having properties.
attr() gives you the value of element as it was defines in the html on page load. It is always recommended to use prop() to get values of elements which is modified via javascript/jquery , as it gives you the original value of an element's current state. Find out more here.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How to write cookies in jquery?
Why are not some scripts and styles loading? : jquery mobile
How can related code be encapsulated?
What is queue() in jquery? Use of queue() in jquery?
What are features of jquery or what can be done using jquery?
What are some of the ways to provide effects? : jQuery Mobile
List the advantage of using minimized version of jquery?
Difference between prop() and attr()? : jQuery Mobile
How can we apply css in even childs of parent node using jquery library?
What is the use of param() method?
Define jquery filter?
What programming language does jquery use?
Define jquery $.ajax() method?
Tell me does jquery 2.0 supports ie? : jquery mobile
What are the methods used to provide effects in jquery?