Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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
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.