5

Possible Duplicate:
.prop() vs .attr()

Is there a difference between an attribute and a property in the jQuery terminology? Is there an example that can clarify this point?

Community
  • 1
  • 1
Simplicity
  • 47,404
  • 98
  • 256
  • 385

1 Answers1

9

Is there a difference between an attribute and a property in the jQuery terminology?

Yes, there is a difference.

For example...

<input type="text" name="age" value="25" />

jsFiddle.

The attribute would be the value attribute as in the markup. You would use attr('value').

The property would be the value property as accessed via the DOM API. You would use prop('value') (strictly speaking, you'd use val()).

Sometimes they can be very similar, but not always.

alex
  • 479,566
  • 201
  • 878
  • 984