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
https://forums.phpfreaks.com/topic/181800-making-button-active-via-javascript/
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 ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.