JQuery DataTables: How to get row index (or nNode) by id tr string?
I have dataTables <table id="myTable">
. I would like fnUpdate()
and fnDestroy()
my lines. each line has an id, for example: <tr id="16">
. For fnUpdate()
/ fnDestroy()
corresponding <tr>
, I need to get this row index. I'm trying to use fnGetPosition()
, but the way I'm trying to do this is not the way to do this:
$("#myTable").fnGetPosition( $("#16") )
leads to
TypeError: nNode.nodeName undefined [Break On This Error] var sNodeName = nNode.nodeName.toUpperCase ();
Which makes sense since fnGetPosition()
expexts nNode (in my case, HTMLTableRowElement).
How to get HTMLTableRowElement with id="16"
?
EDIT: The correct answer to my question is: document.getElementById("16")
. Based on this, I would like to change my question to:
Why
$("#myTable").fnGetPosition( document.getElementById("16") )
works but
$("#myTable").fnGetPosition( $("#16") )
fails?
document.getElementById () returns a DOM object, and all DOM objects will be accessible in essence.
JQuery $ ('# ...') returns a wrapper around a single DOM object or set of DOM objects (depending on the selector) and as such, it does not return the actual DOM object. This makes it easier to work with DOM objects.
The reason you get this error in the second case will be because $ (# ...) is not really a DOM object.