Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I multiple select object variables in jQuery?

Tags:

jquery

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

var tgtCol = $('td[aria-describedby=tblGrid_Subject]');
var tgtHdr = $('#tblGrid_Subject');
$(tgtHdr, tgtCol).attr('colSpan', '3');
like image 947
bcm Avatar asked Sep 10 '10 02:09

bcm


People also ask

Can you select multiple elements in jQuery?

Definition and Usage. The element selector can also be used to select multiple elements. Note: Seperate each element with a comma.

How do you select multiple elements in Javascript?

To select multiple elements, you can use the querySelectorAll() method. Just like the querySelector() method, you usually use it on the document object.

What is $$ in jQuery?

$ is another, which is just an alias to jQuery . $$ is not provided by jQuery. It's provided by other libraries, such as Mootools or Prototype. js. More importantly, $$ is also provided in the console of modern browsers as an alias to document.

How many types of jQuery selectors are available?

So far we have covered only three standard jQuery Selectors.


2 Answers

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');
like image 161
Bennor McCarthy Avatar answered Oct 08 '22 04:10

Bennor McCarthy


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

$('td[aria-describedby=tblGrid_Subject], #tblGrid_Subject').attr('colSpan', '3');
like image 42
wsanville Avatar answered Oct 08 '22 05:10

wsanville