setAttribute()
javascriptCopy codeelement.setAttribute(name, value);htmlCopy code<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>setAttribute() Example</title>
</head>
<body>
<a id="myLink" href="#">Click me!</a>
<script>
// Select the anchor element by its ID
var link = document.getElementById("myLink");
// Set the href attribute dynamically
link.setAttribute("href", "https://example.com");
</script>
</body>
</html>Last updated