onclick = bold

Discussion in 'JavaScript' started by Jamie18, Sep 24, 2007.

  1. #1
    i've got an <a> tag that opens a link in a new window... however i want it to be evident which <a> has been clicked on the previous page, so i'm looking for a way to set the text as bold when it the link is clicked..

    i've tried onclick="this.style.font-weight: bold;" and onclick="this.text.bold()" but neither worked..

    anyone know a way to do this?
     
    Jamie18, Sep 24, 2007 IP
  2. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i figured it out.. sorry for the wasted thread but it was..

    onclick="this.style.fontWeight:'bold';"
     
    Jamie18, Sep 24, 2007 IP
  3. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #3
    Wouldn't it be as effective with CSS?

    
    a:visited
    {
    font-weight:bold;
    }
    
    Code (markup):
    BP
     
    blueparukia, Sep 24, 2007 IP
  4. Awanish

    Awanish Peon

    Messages:
    53
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    True, instead of using an event simply do the style for the visited link.
     
    Awanish, Sep 26, 2007 IP
  5. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    sorry.. i didn't explain what i needed well enough.

    i have 2 windows, one of them contains links, the other opens the pages for the links..

    what i wanted was for any link i open to turn bold, and all the rest of the links to go back to normal, the window with the links is never reloaded either..

    so my solution was to use javascript to set the link as bold onclick and set the previously bold link as normal at the same time.
     
    Jamie18, Sep 26, 2007 IP
  6. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #6
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
      <title>Links</title>
      <style type="text/css">
        .active { font-weight: bold; }
      </style>
    </head>
    <body>
    
      <a href="page1.html" id="link1" onclick="changeActiveStates(this)">Link 1</a>
      <a href="page2.html" id="link2" onclick="changeActiveStates(this)">Link 2</a>
    
      <script type="text/javascript">
      function byId(id) {
        return document.getElementById ? document.getElementById(id) : document.all[id];
      }
      var prevLink = "";
      function changeActiveStates(ele) {
        if (prevLink) byId(prevLink).className = "";
        ele.className = 'active';
        prevLink = ele.id;
      }
      </script>
    </body>
    </html>
    Code (markup):
     
    krt, Sep 26, 2007 IP