Reputation: 1530
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
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
Reputation: 5679
Try the following code.
$('<button>My Button</button>').appendTo('.class1','.class2');
Upvotes: 0
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