Hamid Reza
Hamid Reza

Reputation: 2973

How to add two classes to an existing class with jquery?

I have this element:

<div class="btn-group"></div>

And I have an click event in jquery and I have selected above div and now after selecting the element I want to add two classes named dropdown and open to its btn-group class.

It means I want to have this:

<div class="btn-group dropdown open"></div>

If the element already contains the btn-group class.

How can I do that?

Upvotes: 2

Views: 13019

Answers (3)

Matthias Wegtun
Matthias Wegtun

Reputation: 1261

Getting the class after clicking on btn-group

$('.btn-group').on('click', function(){
    $(this).addClass('dropdown open');
})

Upvotes: 3

sangram parmar
sangram parmar

Reputation: 8726

try this

$('.btn-group').addClass('dropdown');
$('.btn-group').addClass('open');

Upvotes: 2

Arun P Johny
Arun P Johny

Reputation: 388316

Try

$('.btn-group').addClass('dropdown open')

Upvotes: 12

Related Questions