Hi can anyone help?, I want to use JS to add an XHTML id="selected" attribute to the link which is the same as the H1 header on a page. This attribute will be picked up by a CSS file and have a style applied to it to differentiate it as a 'you are here' link.
This is what I did:
<!-- call function from web page -->
<body class="body-class" id="bodyid" onload="you_are_here()">
In the JS file:
// execute function
function you_are_here() {
// get list of anchor links
var a = getElementsByTagName("a");
//get header
var h1 = getElementsByTagName("h1");
// loop through each link looking for a match
for (i=0; i < a.length; i++) {
// if link matches document h1 then set the id attribute on the link to 'selected'
if (a == h1) {
return a.setAttribute("id", "selected");
}
}
}
This style is in the CSS file:
#selected {
background-color:#eeeeee;
}
It didn't work, does anyone know how this can be done with JS?
thanks
Steve