$(this).find("img"); // any img tag child or grandchild etc...$(this).children("img"); //any img tag child that is direct descendant$(this).find("img:first") //any img tag first child or first grandchild etc...$(this).children("img:first") //the first img tag child that is direct descendant$(this).children("img:nth-child(1)") //the img is first direct descendant child$(this).next(); //the img is first direct descendant child
$(document).ready(function() {// When you click the DIV, you take it with "this"$('#my_div').click(function() {console.info('Initializing the tests..');console.log('Method #1: '+$(this).children('img'));console.log('Method #2: '+$(this).find('img'));// Here, i'm selecting the first ocorrence of <IMG>console.log('Method #3: '+$(this).find('img:eq(0)'));});});
$(document).ready(function() {// When you click the DIV, you take it with "this"$('#my_div').click(function() {console.info('Initializing the tests..');console.log('Method #1: '+$(this).children('img'));console.log('Method #2: '+$(this).find('img'));// Here, i'm selecting the first ocorrence of <IMG>console.log('Method #3: '+$(this).find('img:eq(0)'));});});
// Set the click handler on your div$("body").off("click", "#mydiv").on("click", "#mydiv", function() {
// Find the image using.find() and .each()$(this).find("img").each(function() {
var img = this; // "this" is, now, scoped to the image element
// Do something with the image$(this).animate({width: ($(this).width() > 100 ? 100 : $(this).width() + 100) + "px"}, 500);
});
});