Solved

Javascript Modification to change "active" menu buttons

Posted on 2010-11-19
3
402 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
ID: 34175406
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
ID: 34175637
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
ID: 34177918
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

863 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

22 Experts available now in Live!

Get 1:1 Help Now