Search code examples
javascriptjquerycssthispseudo-class

Using this with pseudo selectors jquery


I'd like to know if there is a way to use this with CSS pseudo selectors - (AKA nested elements) in jQuery. Here's what it might look like.

    $('#element').click(function(){
        $(this' .nested').css('height','100px');
    });

But this isn't how the syntax works. I'd just like to know how it would work.


Solution

  • Use find() instead. Example:

    $('#element').click(function(){
        $(this).find('.nested').css('height','100px');
    });