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. The below javascript works, but is there a way to combine the headers into a single jQuery selector?
<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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.