1.

What Is Difference Between Prop And Attr?

Answer»
  • In jQuery both prop() and attr() function is used to set/get the value of specified property of an ELEMENT.
  • The DIFFERENCE in both the functions is that attr() returns the DEFAULT value of the property while the prop() returns the current value of the property.

For EXAMPLE

<input value="My Value" type="text" />

$('input').prop('value', 'Changed Value');

  • .attr('value') will return 'My Value'
  • .prop('value') will return 'Changed Value'

For example

<input value="My Value" type="text" />

$('input').prop('value', 'Changed Value');



Discussion

No Comment Found