5

I am using the DataTables plugin for jQuery and need to get one of the table rows. DataTables has a fnGetNodes function that returns an Array with all of the DOMElements of the table. I would like to use a jQuery selector to find that row (I know the id of the row), but I need to convert the Array to a jQuery Object, is this possible?

Gabriele Petrioli
197k35 gold badges274 silver badges329 bronze badges
asked Jun 5, 2010 at 17:46

3 Answers 3

7

To get a jQuery object from an Array of nodes, you can just pass it to jQuery:

var nodes = [document.documentElement, document.documentElement.firstChild];
var extendedNodes = $(nodes);
answered Jun 5, 2010 at 17:54
Sign up to request clarification or add additional context in comments.

Comments

3

According to http://api.jquery.com/jQuery/ you can do just that:

jQuery( elementArray )
elementArrayAn array containing a set of DOM elements to wrap in a jQuery object.

If it doesn't work, possibly your array is not an actual array, so you can try:

$('#id',$($.makeArray(array)));
answered Jun 5, 2010 at 17:55

Comments

2

Logically you could do it with

var $row = $(dom_array).filter( 
 function(index){ 
 return $(this).attr('id') == 'some_id'; 
 } 
 );

this will return a jQuery object of the row with the specified id.

JJJ
33.2k20 gold badges94 silver badges103 bronze badges
answered Jun 5, 2010 at 17:54

1 Comment

I knew it had to be simple. I prefer using selectors though. So, I went with: $(dom_array).filter('tr[id='+pid+']');

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.