Jquery .val() work to set value for textbox but .attr() does not - Javascript jQuery

Javascript examples for jQuery:Form Text Input

Description

Jquery .val() work to set value for textbox but .attr() does not

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <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.min.js"></script> 
  <script type="text/javascript">
    window.onload=function(){//from   w ww  . ja  v a  2s. co m

$("#TextBoxID2").val("HI Value Change")

    }

      </script> 
 </head> 
 <body> 
  <input type="text" id="TextBoxID1"> 
  <input type="text" id="TextBoxID2">  
 </body>
</html>

Related Tutorials