Change the href for a hyperlink by using its value jQuery - Javascript jQuery

Javascript examples for jQuery:Link

Description

Change the href for a hyperlink by using its value jQuery

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <title>change anchor link</title> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script> 
  <script type="text/javascript">
    window.onload=function(){/*w w w  . j a  v a 2  s . c om*/
if($("a").text() == 'Accept') {
   $("a").attr('href', 'http://www.java2s.com');
}
    }

      </script> 
 </head> 
 <body> 
  <a href="Accept.php">Accept</a>  
 </body>
</html>

Related Tutorials