Add attribute using jQuery
code:
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-git.js"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Add attribute using jQuery</title> </head> <body> First name: <input id="iid" type="text" name="fname" > <input id="button1" type="button" value="Click to add an attribute" />
<script>
$(document).ready(function(){ $('#button1').click(function(){ $('#iid').prop('value', 'input your name here'); }); });
</script> </body> </html>
output:
when you click the button it set attribute value automatically
<input id="iid" type="text" name="fname" value="input your name here "/>
Post a Comment
If you have any doubts, Please let me know
Thanks!