Solved

Javascript Modification to change "active" menu buttons

Posted on 2010-11-19
3
407 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I select this logo using CSS? 6 30
JavaScript Loan Calculator Error 3 19
2 separate CSS animations 2 17
Clear input text 15 9
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

820 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