简体   繁体   English

在jQuery中没有选择器的2个类的目标元素

[英]Target element with 2 classes inside a jquery not selector

I can't seem to get this to work, it is probably pretty simple but here we go: 我似乎无法使它正常工作,这可能很简单,但是我们开始:

This is my selector and I want to look for an element with both the selection[0] and selection[1] class but this does not look for an element that has both. 这是我的选择器,我想查找同时具有selection [0]和selection [1]类的元素,但这并不查找同时具有这两个元素的元素。 As far as I can tell it only grabs the first selection class and looks for that. 据我所知,它只会抓住第一个选择类并进行查找。

$(this).not("." + selection[0], "." + selection[1]).hide();

I've tried manually inputting it like this and it works: 我试过像这样手动输入,它可以正常工作:

$(this).not(".class1.class2").hide();

I'm guessing the comma seperates the selectors and it is going wrong there. 我猜逗号用逗号分隔选择器,并且在那里出错。 How can I achieve the same functionality though? 但是,如何实现相同的功能?

+代替逗号,以将dot [0]连接起来.

$(this).not("." + selection[0] + "." + selection[1]).hide();

This line 这条线

$(this).not("." + selection[0], "." + selection[1]).hide();

has a syntax error (not from JS point of view but jquery selector point of view) 具有语法错误(不是从JS的角度来看,而是从jquery选择器的角度来看)

make it 做了

$(this).not("." + selection[0] + "." + selection[1]).hide(); //replaced comma with + 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM