jQuery:选择一个元素的类和id在同一时间? [英] jQuery: select an element's class and id at the same time?
问题描述
我有一些链接,我想同时选择类和id。
这是因为我有两种不同的行为。当一类链接获得一个类名时,它们以一种方式表现,当相同的链接获得另一个类名时,它们的行为不同。类名是用jquery切换的。
所以我必须能够同时选择一个链接类和id。这是可能吗?
我试过:
$ a .save #country)
没有任何结果。
您可以:
$保存)...
或
$(a#country.save)...
OR
$(a.save#country)...
因此,您可以指定一个必须与ID匹配的选择器和类(以及可能的标记名称和任何其他您想要抛出的)。
I've got some links that I want to select class and id at the same time.
This is because I've got 2 different behaviours. When a class of links got one class name they behave in one way, when the same clas of links got another class name they behave differently. The class names are switch with jquery.
So I have to be able to select a links class AND id at the same time. Is this possible?
I've tried:
$("a .save #country")
without any result.
解决方案You can do:
$("#country.save")...
OR
$("a#country.save")...
OR
$("a.save#country")...
as you prefer.
So yes you can specify a selector that has to match ID and class (and potentially tag name and anything else you want to throw in).
这篇关于jQuery:选择一个元素的类和id在同一时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!