Select class 除了 jquery 中的另一个 class
Select a class except another class in jquery
我想要 select 一个有 .handle class 但没有 .exception class-
的元素
HTML-
<div class="handle exception"> One <div>
<div class="handle"> Two <div>
$(document).on('click', '.handle', function (e) {
//I want to select only 2nd div.
});
有什么帮助吗?
使用 .not
取消选择特定的 class
例如
$(".handle").not(".exception")...
在您的情况下,将如@Mohamed-Yousef 的回答中所述
你可以使用:not
select或
$(document).on('click', '.handle:not(.exception)', function (e) {
//I want to select only 2nd div.
});
或 select 第二个 .handle class 元素你可以使用 :eq(1)
或 nth-child(2)
'.handle:eq(1)' // index start from 0 so 1 to select 2nd one
'.handle:nth-child(2)' // index start from 1 so 2 to select 2nd one
我想要 select 一个有 .handle class 但没有 .exception class-
的元素HTML-
<div class="handle exception"> One <div>
<div class="handle"> Two <div>
$(document).on('click', '.handle', function (e) {
//I want to select only 2nd div.
});
有什么帮助吗?
使用 .not
取消选择特定的 class
例如
$(".handle").not(".exception")...
在您的情况下,将如@Mohamed-Yousef 的回答中所述
你可以使用:not
select或
$(document).on('click', '.handle:not(.exception)', function (e) {
//I want to select only 2nd div.
});
或 select 第二个 .handle class 元素你可以使用 :eq(1)
或 nth-child(2)
'.handle:eq(1)' // index start from 0 so 1 to select 2nd one
'.handle:nth-child(2)' // index start from 1 so 2 to select 2nd one