I’m trying to create a navigation bar with four elements. If the element is currently selected it will have a “red” background image, if it is one of the other 3, it will have a “black” background image. my four tabs are ‘timetable, homework, notifications and sport’ I tried making 8 functions like the 2 below
function setTimeRed()
{
document.getElementById("time").style.ClassName = 'timetable_r';
}
function setTimeBlack()
{
document.getElementById("time").style.ClassName = 'time_r';
}
And then four blocks like this:
function changeTimeButton()
{
var timePath = new String();
timePath = document.getElementById("timetable").style.backgroundImage;
if(timePath == "url(assets/img/tabs/time_black.png)" || timePath == "")
{
setTimeRed();
setHomeBlack();
setNotiBlack();
setSportBlack();
}
else {
}
}
That all looks a bit convoluted. It’s easier to style links like that using CSS or PHP. Have a look at this recent thread which discusses both approaches:
Thanks ralph, my only problem is that this has to function locally, I can’t use any server-side code, I’m quite familiar with php, but a lot less so with JavaScript thus this project is taking some time… Is there a better way to do this in JavaScript, maybe with jquery?
But don’t forget the CSS option, too. It works with JS off, and doesn’t require a big library. (I guess if you are already downloading the library for other purposes, that’s irrelevant, of course.)
The links don’t really help, I think I’m taking the wrong approach… My aim is to have one file that ALL the content is viewed in, with two navigation bars, one at the top, one at the bottom, and a sort of “window” in the middle. The bottom navigation has four links, and the one at the top has three, but the three top links are different depending on what page you are viewing. so when I click the timetable link on the bottom navigation, I get the timetable for the day, with the day link at the top of the page selected. When I click “week” on the top, the ‘Timetable’ stays selected but the the ‘day’ becomes deselected, and the content in the window changes to the week. I don’t need any special effects, or flashes or shiny buttons. I just need this simple page, but I CANNOT load a new page entirely, all the content has to be available through the index.html file. AND it all has to function from a flash drive on any computer, so no online links or content. It’s really confusing me… How would I go about doing this?