TheNone
TheNone

Reputation: 5802

"toggleClass" in my accordion

I have written a jquery script here But there is problem in the $(this).toggleClass("active").next(); section. With this all the header tags will be in "active" class. How can I assign "active" class only for clicked tag? Thanks in advance

Upvotes: 1

Views: 1540

Answers (1)

Nick Craver
Nick Craver

Reputation: 630359

You can remove it from the previously clicked headers by calling .removeClass() on the .siblings(), like this:

$(this).toggleClass("active").siblings().removeClass("active");

You can test it out here.

Upvotes: 4

Related Questions