[英]JQuery, how to combine child selectors?
I have some HTML like the below, and would like to write a javascript function that returns an object composed of all the .header
and span
elements. 我有一些类似下面的HTML,并且想编写一个javascript函数,该函数返回一个由所有
.header
和span
元素组成的对象。 The below javascript works, but is there a way to combine the headers into a single jQuery selector? 下面的javascript可以工作,但是有没有一种方法可以将标头组合到单个jQuery选择器中?
<li>
<div class=".header">
<span>some stuff</span>
</div>
</li>
_getElements: function() {
var temp = $('> li > .header', this.element);
var temp2 = $('> li > .header > span', this.element);
var temp3 = temp.add(temp2);
return temp3;
},
You could just use a comma to select multiple things: 您可以使用逗号选择多个内容:
$('> li > .header, > li > .header > span', this.element);
BTW, i've never seen anyone use the direct child selector ( >
) like that, at the beginning of an expression. 顺便说一句,我从未见过有人在表达式的开头使用直接子选择器(
>
)。 Does it work? 它行得通吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.