<a href=""> <script> var a = document.querySelector('a'), b = 4; if (b == 4) { a.href = "/myLink.html"; } else { a.href = "/otherLink.html"; } </script>