Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toggleclass doesn't seem to toggle class, what am I doing wrong?

Tags:

html

jquery

css

I've been trying to make a button toggle a class, as well as show another div below it.

Here is a jsFiddle example I have made for you.

The first function works perfectly, shows and hides the div, but also I want the button itself to add and remove a class, I thought this would work but I seem to be doing something wrong.

Thanks.

like image 943
Kyle Avatar asked Feb 07 '26 02:02

Kyle


2 Answers

$("this").toggleClass("chev-up");

should be

$(this).toggleClass("chev-up");
like image 118
Reigel Avatar answered Feb 08 '26 15:02

Reigel


Change $("this") to $(this). You don't need the quotation marks in there, as this is a keyword that refers to itself.

like image 40
Calvin Avatar answered Feb 08 '26 17:02

Calvin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!