简体   繁体   中英

How do you set an Href value using JQuery

I am having trouble changing the href attribute of my HTML code using Jquery

My HTML code is

      <div id="main-logo"><a href="http://local.winemag.com"></a></div>

I am using the following JQuery code to change my link but for some reason it's not working.

      $("#main-logo a[href]").attr('href', 'http://www.test.com/');

to get the current value of the href based on the code provided

$("#main-logo a").attr("href");

to set the href new value would be

$("#main-logo a").attr("href","http://www.test.com/");

Make sure you have that line executed once the document is ready:

jQuery(document).ready(function($) {

  //
  $("#main-logo a").attr('href', 'http://www.test.com/');

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM