I am getting undefined in the alert box by this following code where actually i have to get Hello in the alert box. Please correct if any mistakes jQuery tutorial
<input type="text" id="name" value="Hello">
</body>
</html>
//alert.js code//
var print= $('#name').val();
alert(print);
Your code works fine for me. See:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<input type="text" id="name" value="Hello">
https://jsfiddle.net/xb6r3phw/
Try to alert('hello') and check.
Try below script.
$(document).ready(function(){ alert($('#name').val()); })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" id="name" value="Hello">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.