My Simple JS to set "active" Menu |
[eluser]the real rlee[/eluser]
Here's a simple bit of JavaScript which sets the currently active link. Perhaps someone could build this into a helper or library JS: Code: /* Code: <ul id="main-menu">
[eluser]the real rlee[/eluser]
UPDATE: For some reason in the previous version i was using the uri class to give me the current url, when i could have used javascript - this.location.href. Also i've used a modified version of [url="http://dean.edwards.name/weblog/2005/10/add-event2/"]Dean Edwards addEvent()[/url] to limit possible conflict with other code using onload... Here's the code, the forums wouldnt let me upload the files or use correct script tags in the html example but its all there ![]() Code: /* Code: /* Code: <html>
[eluser]wemago[/eluser]
nice work ![]() you did something i was going to do ![]() now i have more time to work in other stuff
[eluser]the real rlee[/eluser]
Thanks, glad to give something back to the community ![]()
[eluser]Jumper[/eluser]
Why not just call directly initMenu() at the bottom of the html body? instead of using this messy event handler ?
[eluser]the real rlee[/eluser]
i just prefer to keep my scripts within the header when possible ![]()
[eluser]Jumper[/eluser]
[quote author="the real rlee" date="1183972297"]i just prefer to keep my scripts within the header when possible ![]() Even at the cost of those big and ugly handler functions? I would make an exception if i were you, but it's a matter of taste ![]()
[eluser]the real rlee[/eluser]
yeah very true, the handler function does over complicate things in this case. Nevertheless a very handy function to avoid collisions with multiple onloads ![]() |
Welcome Guest, Not a member yet? Register Sign In |