I want to target the highlighted "table" of an html to scrape on. However my issue here is that there is now specific id
or class
to target it on.
Is there a way to target that specific table?
I'm targeting the 3rd
<table>
tag
You should use the nth-of-type
pseudo-class.
table:nth-of-type(3) {}
Re edit.
Previously you were asking about CSS, but you've changed the tags on the question and are now asking about JavaScript. You can still use a selector:
document.querySelector("table:nth-of-type(3)")
… but you may see more support for the simple getElementsByTagName
method:
document.getElementsByTagName("table")[2]; // 0 indexed
You could use:
document.getElementsByClassName('MsoNormalTable');
To filter on a specific ID use:
document.getElementById('id');
For more information visit this: Explanation document.getElementByClassName();
If you know that it will always be in the same position, you can use the table:nth-of-type(3)
selector in CSS, which will select the third element of type table
.
table:nth-of-type(3) {
color: red;
}
In JavaScript you would use: document.querySelectorAll('table')[2]
to select the third (arrays begin indexing at 0
) element of type table
on the page.
if your target table always last in parent you can use ::last-of-type
.wordSelection1 table:last-ot-type{border: 1px solid red;}