Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The setAttribute() Method</h2> <a id="myAnchor">Go to w3schools.com</a> <p>Click "add" to add an href attribute to the element above.</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { document.getElementById("myAnchor").setAttribute("href", "https://www.w3schools.com"); } </script> </body> </html>