开发者

Can I multiple select object variables in jQuery?

Something like doesn't work, what's the work around?

var tgtCol = $('td[开发者_Python百科aria-describedby=tblGrid_Subject]');
var tgtHdr = $('#tblGrid_Subject');
$(tgtHdr, tgtCol).attr('colSpan', '3');


var tgtCol = $('td[aria-describedby=tblGrid_Subject]');
var tgtHdr = $('#tblGrid_Subject');
$(tgtHdr).add(tgtCol).attr('colSpan', '3');

This will also work:

var stuff = $('td[aria-describedby=tblGrid_Subject], #tblGrid_Subject');
stuff.attr('colSpan', '3');


You're close, you may combine multiple selectors with a comma, like so:

$('td[aria-describedby=tblGrid_Subject], #tblGrid_Subject').attr('colSpan', '3');


As the first two lines already return a jQuery object, you can just do it like this:

tgtHdr.attr('colSpan', '3');
tgtCol.attr('colSpan', '3');


You can use a multiple selector initially:

$('td[aria-describedby=tblGrid_Subject], #tblGrid_Subject').attr('colSpan', '3');


If it's two selectors, you can use 'merge', but if it's more than two you should use 'each'

// using merge:
$.merge(selector1, selector2) // the rest

// using each:
$([selector1, selector2, selector3, .....etc]).each(function(){
    // your code here
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜