-1

I have a table and I have buttons in every row. if I disable setinterval everything works fine but when I start setinterval I only load page any buttons not working.

<script src="folder/js/jquery-2.1.4.min.js"></script>
<script>

$(document).ready(function() {

var refreshId = setInterval(function() {
    $("#refresh").load(location.href + ' #refresh');
    }, 1000);   

$("#acceptOrderButton").click(function(event){
    clearInterval(refreshId);

    alert ("in");

}); 

});

If I disable Set interval and clear interval I see the alert on button click. What can be the problem?

My Button is inside div. So the problem is it. Is there nay way to do it?

<body>

<table id="refresh">
    <tr>
        <td>
            <button id="acceptOrderButton">click</button>   
        </td>
    </tr>
</table>
</body>
Tugrul
  • 31
  • 6

1 Answers1

-1

Here is the working demo

var refreshId = setInterval(function() {
    $("#refresh").load(location.href + ' #refresh');
    }, 1000);   

$("#acceptOrderButton").click(function(event){
    alert ("in");
    clearInterval(refreshId);

} );
<script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script>
  
<h1 id="acceptOrderButton">
acceptOrderButton
</h1>
Basit
  • 862
  • 1
  • 12
  • 30