1
I used the .toggleClass()
in a div
, after clicking on a button, activate the class "menu-active
", if clicked again, it removes it. So far so good.
Only now beyond that, I need something to check that class is active, if it is, I’d like to leave the tag body
of the theme with a "overflow:hidden
", if not "overflow:auto
".
I don’t know much about js, but I looked at google, and in my case I think . hasClass() doesn’t work. Because like I said, I used . toggleClass() on my div, and I needed you to check if the class was active by following the toggleClass "add/remove", you know? Well, from what I’ve seen hasClass doesn’t work for that.
– Ericki
@Ericki doesn’t know what exactly you researched, but toggleClass is equivalent to addClass and removeClass in jQuery. Therefore, hasClass should work, it will simply check whether or not the element has a certain class.
– BrTkCa
@Ericki, of course the
.hasClass()
will serve in your case, maybe you have gotten confused for you because it takes another selector to use it, and as you have not posted any content of yourhtml
, our friend suggested something that was more logical...but basically you would have to add the classmenu
in your div and work tomenu-active
as it has already done, and your if with the.hasClass
will work perfectly...– Kenny Rafael