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 do you check if an element exists or not in jQuery?
How to check data type of any variable in jQuery?
Differentiate among .empty() vs .remove() vs .detach() in jquery.
What is the difference between bind() and live() function in jquery?
What are the various ajax functions?
Tell me can we have multiple document.ready() function on the same page? : jquery mobile
How to execute jQuery code after the DOM is ready?
Can you call C# code-behind method using jQuery? If yes,then how?
When can jquery be used?
How we can get the input value of an element using jquery?
What is difference between .setinterval() and .delay() ?
What is event.PreventDefault in jQuery?