Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6377473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:52:41+00:00 2026-05-25T01:52:41+00:00

On another question I asked if I could set the font-weight to bold on

  • 0

On another question I asked if I could set the font-weight to bold on a text element when that text is selected. This has been completed much to the avail of @Eric ! But currently, when you click a text, you can happily click another one and both of the text will be bold.

How can I prevent more than one text element from being bold?

Here is my code on JSFiddle: http://jsfiddle.net/6XMzf/ or below:

CSS:

html,body {
    margin: 0;
    padding: 0
}
#background {
    width: 100%; 
    height: 100%; 
    position: absolute; 
    left: 0px; 
    top: 0px; 
    z-index: 0;
    color: white;
}

.stretch {
    width:100%;
    height:100%;
}
.navigationPlaceholder {
    width:100px;
    height: 400px;
    left: 100px;
    top: 100px;
    position: absolute;
}
#navigation {
    background-color: #000000;
}
#navigationText ul {
    font-family: "Yanone Kaffeesatz";
    font-weight: 100;
    text-align: left;
    font-size: 25px;
    color: #b2b2b2;
    left: 25px;
    top: 50px;
    position: absolute;
    line-height: 40px;
    list-style-type: none;
}
.noSelect {
  -moz-user-select: none; /* mozilla browsers */
  -khtml-user-select: none; /* webkit browsers */
}

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>Max Kramer | iOS Developer</title>
        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz" />
    </head>
    <body>
        <div id="background" />
        <div id="navigation" class="navigationPlaceholder">
            <div id="navigationText">
                <ul>
                    <li>iOS</li>
                    <li>Blog</li>
                    <li>About</li>
                    <li>Contact</li>
                </ul>
            </div>
        </div>
        </div>
        <script type="text/javascript">
            var nav = document.getElementById('navigationText');

            var navItems = nav.getElementsByTagName('li');

            for (var i = 0; i < navItems.length; i++) {
                navItems[i].addEventListener('click', function() {
                    this.style.fontWeight = '400';
                }, false);
            }

        </script>
    </body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:52:42+00:00Added an answer on May 25, 2026 at 1:52 am

    If you don’t have a selector engine handy like jQuery and really have to do this in plain Javascript, I would do it like this:

    function addClass(elem, className) {
        if (elem.className.indexOf(className) == -1) {
            elem.className += " " + className;
        }
    }
    
    function removeClass(elem, className) {
        elem.className = elem.className.replace(new RegExp("\\s*" + className), "");
    }
    
    var lastSelected = null;
    
    function initNavClickHandler() {
        var nav = document.getElementById('navigationText');
        var navItems = nav.getElementsByTagName('li');
    
        for (var i = 0; i < navItems.length; i++) {
            navItems[i].addEventListener('click', function() {
                addClass(this, "selected");
                if (lastSelected) {
                    removeClass(lastSelected, "selected");
                }
                lastSelected = this;
            }, false);
        }
    }
    
    initNavClickHandler();
    

    Then, add a CSS rule that controls the selected look:

    .selected {font-weight: 800;}
    

    This is a lot more flexible for styling because you can add as many CSS rules as you want to the .selected class to change/modify it without ever touching your code.

    You can see it work here: http://jsfiddle.net/jfriend00/rrxaQ/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sure this question has already been asked in one form or another, but
This question has been asked before, but the answered ones I could find were
I know that maybe this question has been asked before, but I can't seem
Excuse me if this is a question that has been asked before, if so
I hope that this question has not been asked elsewhere, but I'm having difficulty
sorry if this question has been asked before, I searched but wasn't sure on
I know this question has been asked a couple of times, but there's something
I know this question has been asked a million times in various ways by
This question has been asked before for other languages: Python , PHP and JavaScript
I know this kind of question has been asked many times. Yet I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.