Sorry I am quite novice to Javascript.
When a page has loaded, I would like to get the active link in a menu.
I can’t compare the current url with the address the points to (links trigger connection within the current page).
The idea is to loop through all the a tags (in a table) and check whether the state of the link is active.
An active link diplays differently by default, so I suppose that there is a way to get this info by querying the element properties.
For the moment I am working round it by checking whether the link diplays as a default active link
if (document.getElementById('MyTable').rows[i].style.fontWeight =="bold"){
..some code...
}
This obviously works, but if for some reason the boldness applied regardless of the link status this would fail, so I feel like it is not the most solid method.
I am looking for something like
if (document.getElementById('MyTable').rows[i].cells[0].childNodes[0].active == true){
..some code...
}
The childNodes[0] of the first column cell would be the a tag.
You’re much better off doing this server side or alternately google ‘body class CSS navigation’
And if you’re triggering jumps within the same page just tack on #xyz at the end of the URL and you can compare that in JavaScript.