Making links active in Javascript

后端 未结 3 1402
南旧
南旧 2021-01-13 07:35

I have some problems with Javascript. In fact, I\'m just newbie in that script language so I need some help.. Q: how to make this link active:



        
相关标签:
3条回答
  • 2021-01-13 07:51

    a:active means when you click the link the css properties will apply on the link, instead of using a:active use

    a.visited{color:red;}
    
    0 讨论(0)
  • 2021-01-13 08:03

    Since you're just starting out, I'd suggest you use a library such as jQuery. So, if your HTML is like this:

    <div id="box1" class="box">
    <h3><a name="box1">something</a></h3>
    </div>
    <div id="box2" class="box">
    <h3><a name="box2">something</a></h3>
    </div>
    <div id="box3" class="box">
    <h3><a name="box3">something</a></h3>
    </div>
    

    And you have a CSS class called youarehere:

    .youarehere { color:white; background:green; }
    

    With jQuery you could write something along the lines of:

    $(".box > a").click(function() {             // when clicking any of these links
        $(".box > a").removeClass("youarehere"); // remove highlight from all links
        $(this).addClass("youarehere");          // add highlight to clicked link
    })
    

    In plain JS, it takes a bit more effort to achieve this. Do yourself a favor and don't reinvent the wheel - people have already taken care of this, so use the product of their labor to make your life easier.

    0 讨论(0)
  • 2021-01-13 08:06

    To change the link text color on mouse over use the following css:

    <style type="text/css">
            a:hover{color:Red;}
        </style>
    
    0 讨论(0)
提交回复
热议问题