Solved

Javascript Modification to change "active" menu buttons

Posted on 2010-11-19
3
410 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 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