Home >Web Front-end >JS Tutorial >Summary of special effects code for matching jquery address bar link and a tag link_jquery
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.