I am trying to replace classname after ajax has been loaded (updated to table) , when i did a console log on my code for
$( document ).ajaxComplete(function(e, xhr, settings) {
var x = document.getElementsByTagName("tbody");
console.log(x)
});
it will print this, i am able to access the tag by clicking on it and see that the specific dom is being selected on my web. Everytime after ajax is called, it will refresh the table but not the page.
HTMLCollection(12) [tbody, tbody, tbody.linked-visual-table, tbody, tbody, tbody, tbody, tbody, tbody, tbody, tbody, tbody]
length: 12
0: tbody
1: tbody
2: tbody.linked-visual-table
3: tbody
rows: HTMLCollection(27) [tr.viz-tr-header, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr, tr]
align: ""
ch: ""
chOff: ""
vAlign: ""
title: ""
lang: ""
translate: true
i tried this to log xhr and this is what it returns
{url: "/arc/sqlrun/jsonselect_parallel", type: "POST", isLocal: false, global: true, processData: true, …}
url: "/arc/sqlrun/jsonselect_parallel"
type: "POST"
isLocal: false
global: true
processData: true
async: true
when i tried to select a specific index on my html collection and i did console.log(x[3])
it will print , but i when i click on the tag was print out on my console log, it is not highlighting anything on my browser, i believed that all dom was being replace . what i am trying to achieve is
$( document ).ajaxComplete(function(e, xhr, settings) {
var x = document.getElementsByTagName("tbody");
console.log(x)
//Find td that has string of 'go' and add class green
//Find td that has string of 'Stop' and add class red
});
Ive been trying to tackle this problem for days but i feel i am missing some step. everytime when new data is loaded on table, it will remove classname that was assigned
i have tried queryselector and indexing of array, all have returned Node cannot be found in the current page.
update
i have implemented @manikant gautam solution, it appends to almost all but skip to the one i needed the class to be appended.
$( document ).ajaxComplete(function(e, xhr, settings) {
var x = document.getElementsByTagName("tbody");
//var x = document.querySelectorAll("tbody");
console.log(x)
addClasses();
});
function addClasses(){
var x = document.getElementsByTagName("tbody")
for (var i=0; i<x.length; i++){
x[i].className += " custom";
}
in my console log, it seems it is avoiding any custom class to be appended to that specific tag , but why?
HTMLCollection(12) [tbody, tbody, tbody.linked-visual-table, tbody, tbody, tbody, tbody, tbody, tbody, tbody, tbody, tbody]
length: 12
0: tbody..custom
1: tbody..custom
2: tbody.linked-visual-table.custom
3: tbody
4: tbody..custom
5: tbody..custom
6: tbody..custom
7: tbody..custom
8: tbody..custom
9: tbody..custom
10: tbody..custom
11: tbody..custom
__proto__: HTMLCollection
only at index 3 has values, all the the indexes on tbody other than 3 which has classname assign has no values at all. does this mean, it automatically create a new div after it is refresh on ajax?
HTMLCollection(12) [tbody, tbody, tbody.linked-visual-table, tbody, tbody, tbody, tbody, tbody, tbody, tbody, tbody, tbody]
length: 12
0: tbody..custom
1: tbody..custom
2: tbody.linked-visual-table.custom
3: tbody
rows: HTMLCollection(19)
length: 19
0: tr.viz-tr-header
1: tr
2: tr
3: tr
2
Answers
Try this.
Example
.addClass('Green')
you have to applied after matching condition.