Jump to content

Making button active via javascript ?


Rommeo

Recommended Posts

In my left menu I have css-buttons

my css file is like;

#button {}
#button li {}
#button li active {}

and in my html file

I m using  those buttons like :

<li><a href="Support.html">Support</a></li>
<li><a id="active" href="Order.html">Order</a></li>

here is my problem, if you notice the second line "id" is "active" here.

I m activating it by using php

<li><a id="<?php if($page=='order') echo "active"; ?>" href="Order.html">Order</a></li>

But since I have a long menu, I need to use if statement more than 30 times. So I m looking for easier and faster solution.

 

So is it possible to change the "id" of the anchor via javascript ?

like :

 <a href="www.etc.com/order" onClick="this.id=active">Order</a>

I need your ideas, other options are also welcome. Just trying to find easier and quicker way.

 

Thanks in advance.

Link to comment
Share on other sites

I dont know if this would be a solution for you or not but instead of changing the id I would just add and remove classes. If you have an active class you can just assign it and remove it as needed.

Can you give me an example ?

How will I change the active class ? via JavaScript ? How ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.