Emerge2001
Emerge2001

Reputation: 41

JQuery select an element that contains multiple classes

I'm probably tired but can't get this one figured out. I have a several elements on the page that contain 2 classes like so:

<div class='cen_answer_option, cen_mc'>Some Content</div>

I created a simple event listener in jquery that listens for click on the class cen_answer_option:

$(document).on("click",".cen_answer_option",function(e){
alert($(this).html()); });

If I remove the "cen_mc" class this works. But with the cen_mc class there, I get nothing. Thoughts?

Thanks

Upvotes: 0

Views: 41

Answers (1)

Arunakar Prakash
Arunakar Prakash

Reputation: 183

Your class has a comma , in between. It should be <div class="cen_answer_option cen_mc">Some Content</div>

$(document).on("click",".cen_answer_option",function(e){
alert($(this).html()); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='cen_answer_option cen_mc'>Some Content</div>

Upvotes: 1

Related Questions