0

I'm trying to add a checkbox to header of my table . For this purpose I've written the following lines of codes:

tableHead+='<th> <input type="checkbox" id="select_all"/> </th>';

$("#select_all").click(function(){
    alert('clicked!');
})

html

<div>
    <h5 style="float:left;">Results - Table</h5>
    <button id="download-json" class="btn" style="float:right;"><i class="icon-download"></i> Get JSON</button>
    <button id="download-csv" class="btn" style="float:right;"><i class="icon-download"></i> Get CSV</button>
    </div>
    <br>
    <div id="results_container">
    <p>Execute a query first!</p>
    </div>

</div>

Unfortunately, Altough checkbox appear on my table, when I clicked on it, nothing happens. I mean there is no alert message. What should I do to fix it?

zwlayer
  • 1,752
  • 1
  • 18
  • 41
  • @Tushar could you show me where is the duplicate ? – zwlayer Sep 04 '15 at 08:05
  • 3
    You're adding the checkbox dynamically, so the event is not bound, Try: `$(document).on('click', '#select_all', function() { ....`. Let me know if this solves the issue – Tushar Sep 04 '15 at 08:06
  • @Tushar yes, it works. I did not know binding dynamically requires something else than the normal way. – zwlayer Sep 04 '15 at 08:09

0 Answers0