Hello everyone,
I have a navigation bar. It has some 20 links. I wish to make the current link bold. I mean when I click on the link, I want to make it bold and when I click on something else, I want to make the bold link normal.
How do I do it? I tried using following function which I invoked on onclick event of <a> </a> tag. But when I click on somthing else bold text remains the same.
Can yo suggest some ideas, Please??
here is the script
function selected_option(linkid)
{
document.getElementById(linkid).style.font=“bold”;
}
This is one way to do it
var currElem = null; //will hold the element that is bold now
function BoldText(elem) {
if (elem != currElem) { //do thing if you're clicking on a bold link
if (currElem) //if a link bold right now unbold it
currElem.style.fontWeight='normal';
currElem = elem; //assign this element as the current one
elem.style.fontWeight='bold'; //make the element clicked bold
}
}
and the html
<a href="#" onclick="BoldText(this);">Some LInk</a>
<a href="#" onclick="BoldText(this);">Link 2</a>
hope this helps
Thanks warjockey for your time, but this is not what I am looking for. When I click on link I want to make rest of the links to appear normal. I don’t know how to achieve it.
Perhaps I’m misunderstanding things here, but wont a:active { font-weight: bold; } achieve what you’re wanting?
I tried a:active{font-weight:bold;} too, nothing happened. I started with this only, but it didn’t make any link bold, so I came up with the javascript function.
Thanks though