javascript - Reading the IMG within an A on click jQuery -
I am trying to optimize my script to read the alt attribute of an IMG within one.
For some reason, this is not a work:
$ ("# thumb"). Click (function (event) {event.preventDefault (); var title = $ (this + "IMG"). Etr ("alt"); warning (title);}); This returns the value of [commodity] I appreciate some help, thanks.
$ (this + "IMG") does not select anything, So the warning you are seeing is just an empty jQuery object. You should use the $ (this) .find ("img") which should be selected within img elements select this , i.e. this Anchor element case in $ ("# Thumbs"). Click (function (event) {event.preventDefault (); var title = $ (this) .find ("img"). Attr ("Alt"); Warning (title);});
Comments
Post a Comment