Set a result of a function into <a> element HREF - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

Set a result of a function into <a> element HREF

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function fixURL(el){//from  w  w  w.  j a v a  2s  .c  o m
    var vals = el.rel.split('|');
    el.href = el.href.replace(vals[0],vals[1]);
}

      </script> 
   </head> 
   <body> 
      <a target="_blank" href="https://www.google.com/search?q=html5+Javascript" rel="html5+Javascript|html+css" onclick="fixURL(this)">Test</a>  
   </body>
</html>

Related Tutorials