jQuery .attr retrieving custom attribute returns undefined

前端 未结 5 1511
北荒
北荒 2021-01-18 00:55

i have the following problem using jquery.

I have sth like this

相关标签:
5条回答
  • 2021-01-18 01:20

    Your code appears to work fine in this fiddle, using jQuery 1.6

    0 讨论(0)
  • 2021-01-18 01:33

    To retrieve the value of elements, use val(). Since divs don't have values, you should use data() to set and get data.

    0 讨论(0)
  • 2021-01-18 01:35

    I can confirm this code snippet works perfectly in Chrome 11, Firefox 4 and IE 9 using the jQuery Git version.

    EDIT: For the ones advising prop(), check the docs. Prop() is used for boolean attributes like: checked, disabled etc.

    0 讨论(0)
  • 2021-01-18 01:39

    if using the latest jQuery, try with:

    $.prop(propertyName);

    0 讨论(0)
  • 2021-01-18 01:40

    Yes, since jQuery 1.6 I think you need to use .prop() instead of attr().

    0 讨论(0)
提交回复
热议问题