Passing JavaScript variable in clickable link - Javascript jQuery

Javascript examples for jQuery:Link

Description

Passing JavaScript variable in clickable link

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script> 
  <script type="text/javascript">
        $(document).ready(function () {
            var codes = window.location.href;
            codes= codes.substr(codes.lastIndexOf('/')+1);
            var finalurl = "http://your url/" + codes;
            $('#links').attr('href', finalurl);
        });/*from ww  w .  j a  v a 2 s  . co m*/
    
      </script> 
 </head> 
 <body> 
  <a id="links" href="https://www.google.co.in/">ChangedNextUrl</a>  
 </body>
</html>

Related Tutorials