我想通过单击来切换一个 DIV 类,但不是在单击该 DIV 内的链接时。
我试过这个,但即使点击链接,它也会切换类:
$("ol.compacted .tl_general:not(a)").click(function () {
$(this).toggleClass("re-expanded");
});
我能做什么?提前致谢!
我想通过单击来切换一个 DIV 类,但不是在单击该 DIV 内的链接时。
我试过这个,但即使点击链接,它也会切换类:
$("ol.compacted .tl_general:not(a)").click(function () {
$(this).toggleClass("re-expanded");
});
我能做什么?提前致谢!
单击该 div 内的链接时停止事件传播。
$("ol.compacted .tl_general a").click(function (e) {
e.stopPropagation();
});
确保事件目标是正确的元素。
$("ol.compacted .tl_general").click(function (e) {
var $this = $(this);
if ( $this.is(e.target) ) {
$this.toggleClass("re-expanded");
}
});