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
Explain the difference between $(this) and 'this' in jquery?
Can you please explain the difference between prop and attr? : jquery mobile
What are the two types of CDNs?
How to prevent Right Click option using jquery?
What is the difference between find and children methods in jquery?
Explain jquery.noconflict? : jquery mobile
What is the slowest selector in jQuery?
What is the difference between prop() and attr() in jquery?
Why we need jquery mobile? : jquery mobile
Can we select a element having a specific class in jquery ?
Can we call C# code behind using jQuery?
Name 3 available jquery plugins that bootstrap has in their query plugin library.
What is serialize() in jquery?
Explain each() function in jquery?
How can we give face effect in jquery?