I have a task for which on every click of the button some text is added or updated in the same div.
I have created a dummy code :
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn2").click(function(){
console.log("functionCalled");
var num = $("#numChange").text();
var numInc = num + "1";
var output = "<b>Hello world!</b><button id='btn2'>Set HTML</button><p id='numChange'>" + numInc + "</p>"
$("#changeMe").html(output);
});
});
</script>
</head>
<body>
<p id="test1">This is a paragraph.</p>
<div id="changeMe">
<button id='btn2'>Set HTML</button>
<p id='numChange'>1</p>
</div>
</body>
</html>
On one click of button, the text changes from 1 to 11, but nothing happens on second click and henceforth. I want it to keep changing everytime I click the button, i.e. it should change to 111, then next click 1111 and so on.
I am not able to figure out whats wrong or missing in the code