What is difference between prop and attr?



​ 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

Post New Answer

More jQuery Interview Questions

What is the use of toggle() method in jquery?

0 Answers  


Tell me which program is useful for testing jquery?

0 Answers  


How can we give face effect in jquery?

0 Answers  


Is jquery a w3c standard? : jquery mobile

0 Answers  


How to use jquery library in our asp.net project?

0 Answers  






How method can be called inside code behind using jQuery?

0 Answers  


Why should I use jquery?

0 Answers  


Difference between $(this) and 'this' in jQuery?

1 Answers  


How we can hide a block of html code on a button click using jquery?

0 Answers  


How to select combobox select value and text using jquery?

0 Answers  


Why is not dom ready working for jquery mobile? : jquery mobile

0 Answers  


What is $() in jquery library?

0 Answers  


Categories