Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Evening all,
I'm trying to add a class to a div I have but it is not working for some reason.
$(.example div).addThisClass('example class');
Why isn't this working, it works every other time? Has jQuery changed?
Pls help.
addClass()
addThisClass()
it works every other time
There is no method addThisClass in jQuery. Use addClass:
addThisClass
addClass
$('div.example').addClass('example class');
In Vanilla Javascript, you can use classList:
classList
document.querySelector('div.example').classList.add('example class');
Add a comment
You have to use jQuery addClass() function.
$(".example div").addClass('example class');
It is not addThisClass, but addClass does it:
jQuery
It's this instead of addThisClass
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
addClass()insteadaddThisClass()it works every other timeunless you created your own method with that name, I can guarantee you it didn't.