Home >Web Front-end >JS Tutorial >The special effect of matching jquery address bar link and a label link

The special effect of matching jquery address bar link and a label link

不言
不言Original
2018-07-02 15:56:071654browse

This article mainly introduces the special effects of matching jquery address bar links and a tag links. It has certain reference value. Now I share it with you. Friends in need can refer to it

How to get the address with jquery Column parameters, change the address bar style. Next, through this article, I will share with you a summary of the special effect code for matching the jquery address bar link and a tag link. Friends in need can refer to the following

As mentioned in the title, when it appears With this function, 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 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 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 content is the entire content of this article, I hope you like it.

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

jquery ztree implements the right-click collection function

The function of viewing the full text based on jQuery

Select specific tab based on Jquery easyui

##

The above is the detailed content of The special effect of matching jquery address bar link and a label link. For more information, please follow other related articles on the PHP Chinese website!

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