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 we can get the input value of an element using jquery?
Explain the use jquery.data method?
What is the difference between bind() and live() function in jquery?
How can jquery library be added to pages?
How does jquery mobile theming work? : jquery mobile
Write the code to define a requirejs module with its dependencies.
Explain the difference between find and children methods in jquery?
What is a use of jquery filter?
Explain .on()? : jquery mobile
What are the methods used to provide effects?
Which is the fastest selector in jQuery?
Why is jquery better than javascript?
What is the method used to define the specific character in place of $ sign?
What are the advantage of using cdn? : jquery mobile
What does the jQuery migrate function do?