Special Effect code summary for matching the link in the jquery address bar with the tag link _ jquery-js tutorial

Source: Internet
Author: User
How does jquery obtain the address bar parameters and change the style of the address bar? Next, I will share with you the special effect code Summary of matching the jquery address bar link with the tag link through this article, if you need such a function, click a link and add a style to the link address after the jump, add a special style by adding class as current.

: Click HTML + css3 to jump to and add a style to it:

The 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 call code:

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

In this way, the function is implemented.

Modify the href attribute of tag a in javascript and jquery.

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 all the content of this article. I hope you will like it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.