What is difference between prop and attr?
Answer / 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 |
How to get the value of selected option in jquery?
How to control page titles in jquery mobile? : jquery mobile
What is the advantage of using the minified version of jquery rather than using the conventional one?
Will Events Are Also Copied On Clone In Jquery?
How to find grand children in of an element?
Where can we download JQuery?
Tell me do I need to add the jquery file both at the master page and content page as well?
Is there any advantage of using $.ajax() for ajax call against $.get() or $.post()?
How to write browser specific code using jQuery?
What is event preventdefault () and event stoppropagation () in jquery?
Can you please explain the difference between body onload() and document.ready() function? : jquery mobile
What is the goal of cdn and what are the advantages of using cdn?