user3106675
user3106675

Reputation: 35

How to include 2 class names in a addClass() method in jquery?

I need to include two classes as mentioned below..But it is not working.Could anyone look into the issue and suggest me a solution.

$('.list_Person .Skills').addClass("active");

Thanks in advance.

Upvotes: 0

Views: 196

Answers (6)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Use a comma to achieve what you want. It is called as multiple selector.

Try,

$('.list_Person,.Skills').addClass("active");

If you want to add more than one class to a particular selection,just insert a space between the set of classes and then add it,like below:

$('.class').addClass('class1 class2 class3');

Upvotes: 3

Rohit Agrawal
Rohit Agrawal

Reputation: 5490

if you want to add two new class to a selector

$('.class1').addClass("class2 class3");

and if you want to add two class in selector

  1. both class should be there

     $('.class1').filter('.class2').addClass('class3');
    
  2. either one class

     $('.class1,.class2').addClass('class3');
    

Upvotes: 0

Nishant Mahajan
Nishant Mahajan

Reputation: 264

you can separate multiple classes with the space:

$('.list_Person .Skills').addClass("active secondClass thirdClass");

Upvotes: 0

Milind Anantwar
Milind Anantwar

Reputation: 82231

For adding two classes

$('.list_Person .Skills').addClass("active active2");

For adding In two classes

$('.list_Person,.Skills').addClass("active");

Upvotes: 0

thecodejack
thecodejack

Reputation: 13379

I am assuming you are just jquery begginer and want to select .active elements

$('.active').addClass("list_Person Skills");

Upvotes: 0

Khaled Hamdy
Khaled Hamdy

Reputation: 386

Try this

$('.list_Person').addClass("active").addClass("Skills");

Upvotes: 0

Related Questions