jQuery 1.6 prop() on div's title

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

What is the differnece between doing

$('div').prop('title','whatever'); //set
$('div').prop('title'); //get

and

$('div').attr('title','whatever'); //set
$('div').attr('title'); //get

prop() seems to behave the same as attr() in the case of div attribute. I read the 1.6 documentation for this but i'm still a little confused.

THIS IS NOT EXACT DUPLICATE OF .prop() vs .attr(). This post doesn't answer the question. Please do not close it.


prop and attr do not always give different results. They only give different results when there is a difference between a property and an attribute.

For instance, with the checked attribute/property:

$(':checkbox').prop('checked'); // returns boolean true false
$(':checkbox').attr('checked'); // returns string "checked" or undefined

This is all well explained on prop vs attr .

However, with the title attribute/property, there is no difference. They are both strings, and setting one will set the other to that value.

链接地址: http://www.djcxy.com/p/27538.html

上一篇: 什么时候最好使用`attr()`而不是`.prop()`?

下一篇: jQuery 1.6 prop()对div的标题