Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript Modification to change "active" menu buttons

Posted on 2010-11-19
3
Medium Priority
?
425 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 668 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 668 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 664 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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 …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

886 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