10

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');
2
  • Bennor has got the best answer.. I'll accept once I can (10 mins) Commented Sep 10, 2010 at 2:29
  • The point of putting them in a variable is because I'm using the targets more than once. Commented Sep 10, 2010 at 2:30

5 Answers 5

13
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');
Sign up to request clarification or add additional context in comments.

1 Comment

+1 because it actually answers the question about selecting multiple OBJECTS.
1

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

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

1 Comment

Not if you already have multiple objects and you don't know what events lead up to those objects being created.
1

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');

Comments

0

You can use a multiple selector initially:

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

Comments

0

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
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.