I want to detect an element in a table in HTML, but I can find the table in html(I think), I cannot detect the table...PS: I can not change the HTML.
This is DOM
This is my code
alert(document.getElementsByClassName('ep-dp-dt'));
after, I want to detect the table or use the table, but i can't.. I use the table like this
document.getElementsByClassName('ep-dp-dt').rows
and my programme crashes, it can not find rows.....
In the html like I have posted, How to get and use table html? Could you give me some code? Thank you !
First getElementsByClassName
method returns an HTMLCollection
or NodeList
so to get the table you have to get the element from returned collection like this
var table = document.getElementsByClassName('ep-dp-dt')[0];
And then you can get and iterate through rows of table element, something like this
for (var i = 0;i < table.rows.length; i++) {
var row = table.rows[i];
}