开发者

Highlight a # section in a page - jQuery

I have a simple html page

<html>
<div id="d1>Content开发者_运维知识库</div>
<div id="d2>Content</div>
<div id="d3>Content</div>
<a href="page.html#d1">D1</a> <a href="page.html#d2">D2</a> <a href="page.html#d3">D3</a>
</html>

I want to highlight the selected div, with my script

<script>
var divID=window.location.href.split('#')[1];
$(divID).blahblahEffect;
<script>

The problem is this works only the first time when i moved from X page to page.html, after going to page.html if i click on any Links it does not show the effect.


try

CSS

.highlight{ background-color :#FCFC9F; }

jQuery

$("a").click(function (e) {
   $('div').removeClass('highlight');
   var hashId=this.hash.substr(1);
   $('#'+hashId).addClass('highlight');           
   e.preventDefault();
});

DEMO

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜