1

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.

3
  • 1
    addClass() instead addThisClass() Commented Jul 8, 2015 at 8:23
  • 2
    Come on. This is a way too easy thing to ask. Please google it first. Commented Jul 8, 2015 at 8:25
  • it works every other time unless you created your own method with that name, I can guarantee you it didn't. Commented Jul 8, 2015 at 8:30

4 Answers 4

1

There is no method addThisClass in jQuery. Use addClass:

$('div.example').addClass('example class');

In Vanilla Javascript, you can use classList:

document.querySelector('div.example').classList.add('example class');
Sign up to request clarification or add additional context in comments.

Comments

1

You have to use jQuery addClass() function.

$(".example div").addClass('example class');

Comments

1

It is not addThisClass, but addClass does it:

$('div.example').addClass('example class');

2 Comments

Has this always been the case? I'm sure it used to work.
@samjohnsonmw No, addThisClass was never part of jQuery
0

It's this instead of addThisClass

$('div.example').addClass('example class');

getwrecked

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.