'Simple jquery not working to print the input value

Here is a simple code which takes input and print it on the same page. But it is not working when I click on button. Please help regarding this.

<html>
<head>
<script>
function changeHTML() {
    $("#withjQuery").html($("#theInput").val());
}

</script>

<body>
<input type='text' id='theInput' value='Write here' />

<input type='button' onClick='changeHTML();' value='See what you wrote with jQuery.html'/>

<div id="withjQuery"></div>

</body>

</head>


Solution 1:[1]

You do not have jQuery library included in the page

Add

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

ex

<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
function changeHTML() {
    $("#withjQuery").html($("#theInput").val());
}

</script>

</head>

<body>
<input type='text' id='theInput' value='Write here' />

<input type='button' onClick='changeHTML();' value='See what you wrote with jQuery.html'/>

<div id="withjQuery"></div>

</body>
</html>

Demo: Fiddle

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arun P Johny