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

How can events be prevented from stopping to work after an ajax request?

0 Answers  


What is the difference between prop and attr?

0 Answers  


How to use css() in jquery?

0 Answers  


What are the advantages of method chaining in jquery?

0 Answers  


What were the biggest challenges of getting the jQuery 1.7 release ?

0 Answers  






What is the difference between settimeout() and setinterval() methods?

0 Answers  


Define jquery connect?

0 Answers  


Explain the difference between jquery's ready and holdready?

0 Answers  


Explain jquery connect?

0 Answers  


Can we call c# codebehind method using jquery?

0 Answers  


Is it possible to use our own specific character in the place of $ sign in jquery? : jquery mobile

0 Answers  


What is a filter in jquery? Explain

0 Answers  


Categories