Question

Given the following HTML,

<div class="a">
    <div class="b"></div>
    <div class="c"></div>
    <div class="d"></div>
</div>

How would I write an .on event selector that will fire for b and c, but not d?

I've tried:

$(document).on("click", ".a .b.c", function () { 
    alert('test');
 });

but this doesn't seem to work.

Était-ce utile?

La solution

If you want to specifically target .b and .c under .a:

$(document).on("click", ".a .b, .a .c", function () { 
    alert('test');
 });
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top