Calvin Ananda
Calvin Ananda

Reputation: 1530

Append button into 2 class

I want to append my button into div with .class1 and .class2

<div class="class1"></div>

<div class="class2"></div>

I try like this :

$(".class1", ".class2").append('<button>My Button</button>');

How to do that?

Upvotes: 0

Views: 54

Answers (4)

Negi Rox
Negi Rox

Reputation: 3922

it should be

$(".class1, .class2").append('<button>My Button</button>');

please refer below link for more understanding of multiple selector

https://api.jquery.com/multiple-selector/

Upvotes: 0

Lalit
Lalit

Reputation: 1369

Replace $(".class1", ".class2") to $(".class1, .class2")

Upvotes: 1

Imesh Chandrasiri
Imesh Chandrasiri

Reputation: 5679

Try the following code.

$('<button>My Button</button>').appendTo('.class1','.class2');

Upvotes: 0

asdf_enel_hak
asdf_enel_hak

Reputation: 7640

$(".class1", ".class2") should go to $(".class1, .class2")

$(".class1, .class2").append('<button>My Button</button>');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="class1"></div>

<div class="class2"></div>

Upvotes: 1

Related Questions