質問

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.

役に立ちましたか?

解決

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

$(document).on("click", ".a .b, .a .c", function () { 
    alert('test');
 });
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top