Pregunta

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.

¿Fue útil?

Solución

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

$(document).on("click", ".a .b, .a .c", function () { 
    alert('test');
 });
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top