Need help with ugly nesting
How do I select the src of the image tag in the following code? I can开发者_运维问答't seem to get it right!
<li id="user001">
<div class="profile">
<span class="profileImage">
<img src="ladida.png" />
</span>
</div>
</li>
var src = $('li#user001 img').attr('src');
Or do you mean something else?
var profileImageSrc = $("#user001 .profile .profileImage img").attr("src");
var profileImageSrc = $('.profile .profileImage img').attr('src');
But this assumes there's only one image. Since it's in a class profileImage
there could be more than one, then you may have to rethink how you're going to handle this.
$("#user001 .profile .profileImage img").attr("src");
Try this:
alert($(".profile .profileImage img").attr("src"));
精彩评论