Having a layout similar to this
<div id="..."><img src="..."></div>
The jQuery constructor accepts a 2nd parameter called context which can be used to override the context of the selection.
jQuery("img", this);
Which is the same as using .find() like this:
jQuery(this).find("img");
If the imgs you desire are only direct descendants of the clicked element, you can also use .children():
jQuery(this).children("img");
OR
You could also use
jQuery(this).find('img');
which would return all imgs that are descendants of the div
If you need to get the first img that's down exactly one level, you can do
jQuery(this).children("img:first")
<div id="..."><img src="..."></div>
The jQuery constructor accepts a 2nd parameter called context which can be used to override the context of the selection.
jQuery("img", this);
Which is the same as using .find() like this:
jQuery(this).find("img");
If the imgs you desire are only direct descendants of the clicked element, you can also use .children():
jQuery(this).children("img");
OR
You could also use
jQuery(this).find('img');
which would return all imgs that are descendants of the div
If you need to get the first img that's down exactly one level, you can do
jQuery(this).children("img:first")
No comments:
Post a Comment