Solved

Javascript Modification to change "active" menu buttons

Posted on 2010-11-19
3
399 Views
Last Modified: 2012-05-10
I am trying to implement an accordion menu with nothing but html, css, and javascript.
http://test.gunold.com

So far so good. However, the boss has requested that there be some way to "make the 'active' page's menu buttons be different so people can see where they are".

Is it possible to edit this javascript so that I can style the "active" buttons in css? I haven't been able to find a way to do it with just the html or css, so this is my Hail Mary pass. If this doesn't work, I'm going to have to scrap the whole menu and use something else. Not a big deal for you developers out there, but for us measly designers, I'm not looking forward to it.

SO - I first need to know if what I want to do is even possible. Second I need to know if anyone out there can help me (if it's simple) or, if complicated, how much you would charge to do it.

Thank you in advance for responding. PLEASE NOTE: I'm new to EE and only a designer, NOT a developer. So, please be kind, and speak in simple English.
0
Comment
Question by:sulky
3 Comments
 
LVL 7

Accepted Solution

by:
armchang earned 167 total points
Comment Utility
Question:Is it possible to edit this javascript so that I can style the "active" buttons in css?

Yes, it is possible. In Javascript, you can do like this:

document.getElementById("MyElement").className += " MyClass";

Open in new window


where the MyElement is the name of the HTML Control, e.g. Button, Textbox, etc. If you do want to change an elements class during a button click, you can also do this:

<script type="text/javascript">
    function changeClass()
    {
        // code examples from above
    }
</script>
...
<button onclick="changeClass()">My Button</button>

Open in new window

0
 
LVL 18

Assisted Solution

by:Sudaraka Wijesinghe
Sudaraka Wijesinghe earned 167 total points
Comment Utility
And in this case you probably can compare the current url (location.href) to with the href of the A tag and determine if you are on the page referenced by that link.
0
 
LVL 44

Assisted Solution

by:scrathcyboy
scrathcyboy earned 166 total points
Comment Utility
The way I did this for a website is real simple.

Each HTML page knows its own name, correct?  So you simply HIGHLIGHT the link to that page in the coding for each page.

Menu -- Page A -- Page B -- Page C -- Page D

Page D, in the CSS, you simply change the highlighting of Page D to bright red, or something obvious.
You can do this in javascript too, as a universal routine, but you don't have to.

I found it simpler for each page to highlight its own menu link -- it was too easy !!
Just change 2 lines of code in the CSS -- it was so obvious, I didn't bother with a universal routine.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now