jQuery - attribute vs. property [duplicate]
Possible Duplicate:
.prop() vs .attr()
Is there a difference between an attribute
and a pr开发者_运维百科operty
in the jQuery
terminology? Is there an example that can clarify this point?
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.
精彩评论