Pedro Cavaleiro
Pedro Cavaleiro

Reputation: 932

Select an tag with $(this)

I have the following code

$("#accordian h3").click(function(){            
        $("#accordian ul ul").slideUp();            
            if(!$(this).next().is(":visible"))
            {
                $(this).next().slideDown(); 
                $(this).addClass('fa-chevron-up');
            }
        })
    })

And in this case corresponds to an header tag (h3) that in the text has another tag (<i>) that needs to be changed... the problem here is that I'm not being able to get the I tag.

I've tryed $(this + ' i').... but no luck. This is the error logged to the console

Uncaught Error: Syntax error, unrecognized expression: [object HTMLHeadingElement] i

Upvotes: 0

Views: 43

Answers (2)

Fillip Peyton
Fillip Peyton

Reputation: 3657

The i tag is within each of the h3's, correct? If so:

$('i', this)...

This makes use of context when making a Jquery selector.

Upvotes: 1

Michał Dudak
Michał Dudak

Reputation: 5048

I'm not entirely sure what you're trying to achieve. From what I understood, trying $(this).find("i") may solve your problem.

Upvotes: 1

Related Questions