Get javascript generated value in href - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

Get javascript generated value in href

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body onload="myFunction();">  
      <a id="share_url" href="https://www.facebook.com/">Share</a> 
      <script>
        function myFunction() {//from   www. ja  va  2  s. c o m
            var el = document.getElementById("share_url");
            el.href += window.location.host;
        }
    
      </script>   
   </body>
</html>

Related Tutorials