$(this) Selector And Children In jQuery

Here we consider how to use $(this) selector and children for finding elements in jQuery. Lets start with one example here. Suppose we have an image inside div as shown here.

$(this) Selector And Children In jQuery, $this Selector And Children In jQuery, $(this) And Children In jQuery, $(this) Selector And find In jQuery, $(this) Selector And Children, $(this) Selector And find, Find Elements Using $(this) Selector And Children, find and $(this) Selector In jQuery, $(this) Selector In jQuery, Children In jQuery, find In jQuery

When we click inside this Div, we have to fadeout and fadein the image. This can be done in jquery by using a combination of $(this) and Children. We can detect a click inside Div using jQuery Click event. Inside Click event, to get the image, we can use Children or find.

$(function () {
     $('#parentDiv').click(function(){
         $(this).children('img').fadeOut().fadeIn();
     })
});



$(function () {
     $('#parentDiv').click(function(){
         $(this).find('img').fadeOut().fadeIn();
     })
});



Instead of children, we can make use of jQuery find as shown above. By this way, we can use $(this) selector and children for finding elements in jQuery.