How to get the children of the $(this) selector?

I have a layout similar to this:

<div id=...><img src=...></div> 

and would like to use a 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?

Text Copied From stackoverflow.com
on : Thu, Nov 20, 2008 Views : 1641424

Accepted Answer

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);
 
Text Copied From stackoverflow.com
on : Thu, Nov 20, 2008

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp