Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

combine two jquery select statements

how can i merge the results of two select statments with jquery?

for example i have

var previous = $(this).prev('td');
var next = $(this).next('td');

how do i then combine the two sets of results into one?

like image 391
callum.bennett Avatar asked May 10 '11 13:05

callum.bennett


3 Answers

var all = $.merge(previous, next);
like image 64
fearofawhackplanet Avatar answered Oct 21 '22 07:10

fearofawhackplanet


Try:

var all=$(this).prev('td').add( $(this).next('td') );
like image 34
johndodo Avatar answered Oct 21 '22 06:10

johndodo


You can use empty collection

var previous = $(this).prev('td'),
    next = $(this).next('td'),
    buttons = $().add(previous).add(next);

Example: http://jsfiddle.net/UBnMm/

Alternatively:

var buttons = $(this).prev('td').add($(this).next('td'));
like image 3
Adam Kiss Avatar answered Oct 21 '22 05:10

Adam Kiss