Skip to content

Instantly share code, notes, and snippets.

@sdoro
Last active January 14, 2018 15:13
Show Gist options
  • Save sdoro/ab41e3df9466a7fd6c7e101ffc1b79b8 to your computer and use it in GitHub Desktop.
Save sdoro/ab41e3df9466a7fd6c7e101ffc1b79b8 to your computer and use it in GitHub Desktop.
Set Attribute
<a id="myLink" href="http:www.bing.com">Go to my favorite site</a>
document.getElementById("myLink").setAttribute("href", "http://www.microsoft.com");
var
a = document.getElementById("myLink");
a.setAttribute("href", "http://netkit.org");

Set Attribute

A Pen by Bre'Ana Deen on CodePen.

License.

The HTML page in the following example contains a link that points to "http://www.bing.com".

Use JavaScript to modify the hyperlink so that it instead points to your favorite website.

TIP: How can you access the element?

TIP: You'll need to use the href attribute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment