JQuery.attr returns user attribute return undefined

I have the following problem using jquery.

It seems to me like

<div id="yxz" value="1"> <span class="delete"></span> </div> 

I now have fn, but it only returns “undefined”, however it returns an identifier or class if I ask for it.

 $(".delete").click(function(){ alert($(this).parent("div").attr("value")); }); 

I used this value with the same attr attribute. This has to do with me using jquery 1.6.1 instead of 1.5.2.

Thank you for your help.

+8
jquery attr
source share
5 answers

To get the value of the elements, use val () . Since divs have no values, you must use data () to set and retrieve data.

+3
source share

I can confirm that this piece of code works fine in Chrome 11, Firefox 4 and IE 9 using the jQuery Git version.

EDIT: for those advising prop (), check out the docs . Prop () is used for boolean attributes such as: checked, disabled, etc.

+4
source share

if using the latest jQuery try using

$.prop(propertyName);

0
source share

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

0
source share

Your code seems to work fine in this script using jQuery 1.6

0
source share

All Articles