Forum Moderators: open
im having probs again, simply trying to get to the src of an img via the dom.
HTML is
<a href="javascript:alert(this.firstChild.src) ;"> <img src="images/image01.jpg" alt="." /></a>
all i want to do is get to the image src from the link via this.somthing..
firstChild.src isnt working?
stuck
any help much appreciated
nat.
<a href="#" onclick="alert(this.firstChild.src);return false;"><img src="images/image01.jpg" alt="." /></a>
<img src="images/image01.jpg" alt="." onclick="alert(this.src)" style="cursor:pointer;cursor:hand;"/> With #1, Mozilla can occasionally create phantom empty text nodes that could mess up the call to firstChild. Here for instance:
<a>
<img>
Try keeping it more like this, to be on the safe side:
<a><img>
or even
<a><
img>