Home  >  Article  >  Web Front-end  >  Summary of special effects code for matching jquery address bar link and a tag link_jquery

Summary of special effects code for matching jquery address bar link and a tag link_jquery

WBOY
WBOYOriginal
2016-05-16 15:43:01944browse

As mentioned in the title, when such a function appears, after clicking a link, add a style to the link address after the jump, and add a special style by adding class as current.

As shown in the picture: After clicking on the HTML css3 jump, add the picture style to it:

js code is as follows:

var currUrl = window.location.href;
   var currStyle = function (links){
     links.each(function(){
        var url = $(this).attr('href');
        if (currUrl.indexOf(url) != -1){
          $(this).addClass("current");
          return false;
        }
     });
}

How to call it?

The following jquery calling code:

$(function(){
  currStyle($("#sidebar .list a"));
})

This achieves the function as shown in the picture.

Javascript and jquery modify the href attribute of the a tag

The javascript code is as follows:

document.getElementById("myId").setAttribute("href","www.xxx.com"); 
document.getElementById("myId").href = "www.xxx.com"; 

jquery: The code is as follows:

$("#myId").attr("href","www.xxx.com"); 

The above is the entire content of this article, I hope you all like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn