querySelector not working
querySelector not working
1j2o3y
Posts: 7Questions: 1Answers: 0
test case at
https://live.datatables.net/yebelasu/1/edit
here trying to use the below code
var oddtd = document.querySelectorAll('table.display tbody tr:nth-child(odd) td');
oddtd.innerHTML = 'some other value';
but nothing changes.
here trying to get 'some other value' in each odd rows td cells.
any solution with same code like document.querySelectorAll ?
Answers
I'm not clear what you're trying to achieve here. If you change the HTML of the table once DataTables has been initialised, it means that DataTables isn't aware of that change so can't factor that value in to any searching or ordering results, plus as soon as the table is redrawn, say because the page changes, that data will be lost.
If you want to change the data once the table has been initialised, use the API methods, such as
cell().data()
,row().data()
, orcolumn.data()
,Colin
So it is not possible to interact with the table with querySelectorAll ?
What is the correct way to mention all even rows as a variable ?
Is it the below following is right ?
vat treven = table.rows (even);
Or how to mention it with querySelectorAll ?
like document.querySelectorAll('.display tr:nth-child (even')
You can interact with the table using QSA, but you'll run into a bunch of problems - e.g.:
Use
rows().nodes()
if you want access to thetr
elements for the table.What is it you actually want to do?
Allan
Looking to access like this as mentioned above
What is the correct way to mention all even rows as a variable ?
Is it the below following is right ?
vat treven = table.rows (even);
Or how to mention it with querySelectorAll ?
like document.querySelectorAll('.display tr:nth-child (even')
hope it is clear now ?
It would help here if you explain what you're trying to do, as Allan and I are explaining what you're trying to do probably isn't the correct way to do it. Do you just want to style odd/even rows? If so, you can use
createdRow
for that (there's an example on the link doing just that).If you're trying to do something else, please let us know and we can advise.
Colin
Just to add to what Colin has said, if you simply want even rows use:
See the
row-selector
documentation for all the selectors you can use.Note that you will most likely want to account for ordering and filtering as well - the
selector-modifier
is used for that - e.g.:And keep in mind that order can change as the user interacts with the table.
So yes, please tell us what your intention is, and we can help point you in the right direction, rather than just guessing.
Allan
there is no hidden secrets there as you guess something like.
The questions was clearly mention two times as above.
and that's truth as well - written over above 2 times.
Fair enough. We've supplied answers to your questions. Use the API.
Allan
cheers