jquery: .attr() fails for child element
Posted
by
user984003
on Stack Overflow
See other posts from Stack Overflow
or by user984003
Published on 2012-10-13T09:27:30Z
Indexed on
2012/10/13
9:37 UTC
Read the original article
Hit count: 162
jQuery
|jquery-attributes
I'm going crazy staring at this. I need to change the attribute of an element, something which I have done many times before. But it fails. Now I can't even get jquery to show me the attribute that it has. Does it have to do with what is returned by find()?
var c = new_photo_div.find('[class = photo]')[0];
alert(c);
alert(new_photo_div.attr('class'));
alert(c.attr('class'));
The first alert correctly identifies the element: Object HTMLImageElement
The second alert correctly gives me the class of new_photo_div.
The third alert fails. No alert.
I think it should say: photo
© Stack Overflow or respective owner