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 |
What is a dom in jquery? How can we make sure that dom is ready?
What is meant by a deep copy? : jQuery Mobile
Why is only the first page of multi page document loaded? : jquery mobile
What is the purpose of jquery?
How does the jQuery pushStack function work?
What are the two types of CDNs?
You get "jquery is not defined" or "$ is not defined" error. What could be the reason?
What is the basic requirement to start with the jquery?
Explain various methods to make ajax request in jquery?
Tell me can we have multiple document.ready() function on the same page? : jquery mobile
How can jquery library be added to pages? Write a basic jquery code?
Difference between parent() and parents() in jQuery?