jquery - Button function only works on first click -


i trying button work throughout multiple clicks change displaying users on every click button working on first click.

i have hunch either has got ajax or fact each time button clicked button drawn.

i can verify getdata.php working fist click.

html button:

<button id="search">seach</button> 

jquery function button:

document.getelementbyid('search').addeventlistener('click', function (e) {     var info1= document.getelementbyid("datainput").value;     var div = document.getelementbyid("contentdisplay");      //removes current data 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";             }         }     }); }); 

fast, ugly , not tested

document.getelementbyid('search').addeventlistener('click', clickforthebutton);  function clickforthebutton(){     var info1= document.getelementbyid("datainput").value;     var div = document.getelementbyid("contentdisplay");      //removes current data 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.getelementbyid('search').addeventlistener('click', clickforthebutton);         }     }); } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -