Search code examples
javascriptjqueryjquery-selectors

In a table, select tr#myId and the nextone


How can I put together in the selector to select a tr by id and the next one?

So far:

var item = $('tr#CP') /*  Selects the item */

var nextitem = $('tr#CP').next('tr')  /* selects next*/ 

but how can I select both?


Solution

  • $("#CP").next('tr').addBack();
    

    The tr# is not necessary because there can be only one #CP anyway. .addBack "adds back" the original selector to the collection.