I am trying to get a button to work throughout multiple clicks to change what is displaying to the users on every click but the button is only working on the first click.
I have a hunch that it either has got to do with the Ajax or the fact that each time that the button is clicked the button too is drawn.
I can verify that getData.php is working properly for the fist click.
HTML for the button:
<button id="search">Seach</button>
Jquery function for the button:
document.getElementById('search').addEventListener('click', function (e) {
var info1= document.getElementById("dataInput").value;
var div = document.getElementById("contentDisplay");
//removes the current data that is displaying
while( div.hasChildNodes() ){
div.removeChild(div.lastChild);
}
var midHTML;
$.ajax({
async: false,
type: 'POST',
url: 'getData.php',
data: {key: "Search", info: info1},
success: function(data) {
if(data.length > 10){
div.innerHTML = HTML+data;
} else {
div.innerHTML = "No data";
}
}
});
});
$(document).on('click', 'button.search', handlerFunc);