admin管理员组文章数量:1323348
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:
<a href="#box1">something</a>
this link is just link to the div which is located in index.html file, so there is no loading of page. and here is the div
<div id="box1" class="box">
<h3><a name="box1">something</a></h3>
</div>
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:
<a href="#box1">something</a>
this link is just link to the div which is located in index.html file, so there is no loading of page. and here is the div
<div id="box1" class="box">
<h3><a name="box1">something</a></h3>
</div>
Share
Improve this question
asked Jun 19, 2012 at 9:47
Zeid SelimovicZeid Selimovic
8534 gold badges13 silver badges19 bronze badges
2
-
1
What do you mean by
making active
– Rab Commented Jun 19, 2012 at 9:49 - For example to change link's background color in order to show user where is he/she located.. in css there is this snap of code a:active {background:#fff;} but it doesnt work because there is no loading of page – Zeid Selimovic Commented Jun 19, 2012 at 9:51
3 Answers
Reset to default 3Since 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.
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;}
To change the link text color on mouse over use the following css:
<style type="text/css">
a:hover{color:Red;}
</style>
本文标签: cssMaking links active in JavascriptStack Overflow
版权声明:本文标题:css - Making links active in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742130550a2422138.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论