0

First disclosure: I have a lot of scripts running on this particular page.

I have a div of text that I have on page load, now there is a specific link which is toggled to this text, based on clicking on the link. WHEN the page is loaded, I want just the link to be a certain color.

Here is what I have for the text so far... which is displaying on pageload:

<script> window.onload=function showDiv() { document.getElementById('d1').style.display = "block"; } </script> 

Now I need to have my link a specific color on page load, but that color must be able to change back to its CSS default when another link is clicked:

<a href="javascript:unhide('d1');" onClick="changeLinkColor(this)">Innovative Design Methodology</a> 

Like I said, there are other scripts I have running on this page, hence you see in the link.

Just for fun, here's my other code (toggling text & highlighting code):

<script type="text/javascript"> var currentItem; function unhide(divID) { if (currentItem) { currentItem.className = 'hidden'; currentItem = null; } var item = document.getElementById(divID); if (item) { item.className = 'unhidden'; currentItem = item; } } </script> <script type="text/javascript"> var currentLink = null; function changeLinkColor(link){ if(currentLink!=null){ currentLink.style.color = link.style.color; } link.style.color = '#f5b331'; currentLink = link; } </script> 

1 Answer 1

1

You could add a css class on the anchor tag initially (which has your custom styling) and remove it on click on any of the links.

Your HTML

<a id="link1" class='CustomColor'></a> 

And your CSS

.CustomColor { color:red; } 

And On click of any link,

document.getElementById("link1").className = document.getElementById("link1").className.replace('CustomColor',''); 
Sign up to request clarification or add additional context in comments.

1 Comment

Beat me to it :) You forgot the dot before the class decleration

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.