snippetjavascriptCritical
How to get the children of the $(this) selector?
Viewed 0 times
howthethischildrenselectorget
Problem
I have a layout similar to this, and would like to use a
To get the
How can I get the child
jQuery selector to select the child img inside the div on click.
To get the
div, I've got this selector:$(this)
How can I get the child
img using a selector?Solution
The jQuery constructor accepts a 2nd parameter called
Which is the same as using
If the imgs you desire are only direct descendants of the clicked element, you can also use
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");Code Snippets
jQuery("img", this);jQuery(this).find("img");jQuery(this).children("img");Context
Stack Overflow Q#306583, score: 2986
Revisions (0)
No revisions yet.