Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 15:43:01
Original
943 people have browsed it

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;
        }
     });
}
Copy after login

How to call it?

The following jquery calling code:

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

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"; 
Copy after login

jquery: The code is as follows:

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

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!