在我的jquery脚本中,我试图从选择器中排除一个项及其所有父项:
$(".Navigation-list--dropdown").not($(this).parent()).addClass('is-hidden');
但是它没有用,有谁知道为什么?
这是完整的脚本:
$(document).ready(function() {
// When a dropdown trigger is clicked
$('.Navigation-link--dropdownTrigger').click(function(e) {
// If its sibling dropdown list is hidden
if( $(this).siblings('.Navigation-list--dropdown').hasClass('is-hidden') ){
// Hide all other dropdown lists, except the clicked list and its parents
$(".Navigation-list--dropdown").not($(this).parent()).addClass('is-hidden');
// unhide only the dropdown whose trigger was clicked
$(this).siblings('.Navigation-list--dropdown').removeClass('is-hidden');
}
});