jQuery:如何在此处选择具有特定类的元素? [英] jQuery:How to select elements with particular class here?
问题描述
HTML像这样:
<span class="someClass position1" >span1</span>
<span class="someClass" >span2</span>
<span class="someClass" >span3</span>
<span class="someClass position2" >span4</span>
<span class="someClass" >span5</span>
<span class="someClass position4" >span6</span>
<span class="someClass position10" >span7</span>
<span class="someClass" >span8</span>
<span class="someClass position12" >span9</span>
现在,使用jQuery,如何仅更改具有类position
+ SomeINTEGER 的那些元素的backgroundColor
?
Now, using jQuery, how will I change the backgroundColor
of only those elements which have the class position
+SomeINTEGER?
我想选择所有类别为poistion
+ TheRespectiveInteger
I want to select all the elements with the class poistion
+TheRespectiveInteger
推荐答案
我假设您要更改 all 元素的背景,这些元素具有与该模式匹配的类-不仅仅是针对一种模式特定号码.
I'm assuming you want to change the background of all the elements that have a class matching that pattern - not just for one particular number.
通过将class
视为另一个属性并对值进行部分匹配,可能有一种 hacky 方式.
There is probably a hacky way to do this by treating class
as just another attribute and doing a partial match against the value.
但是,更好的解决方案是添加另一个可以选择的类.也许在添加positionX
类的同时还添加了positioned
类.
However a better solution is to add another class that you can select on. Perhaps have whatever is adding the positionX
classes also add a positioned
class at the same time.
这篇关于jQuery:如何在此处选择具有特定类的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!