Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/');
like image 956
Mariton Avatar asked Jan 04 '23 11:01

Mariton


1 Answers

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/");

like image 55
linc Avatar answered Jan 07 '23 10:01

linc