title: How to stop DataTable from sorting on click of child element dynamically added to the header?
body: <p>This questions sounds already been answered. </p>
  
  <p>Been looking for answers and I keep getting back to <code>event.stopPropagation()</code> answer. But why does it doesn't work on this fiddle? Am I missing something?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function(){
    $('#test-table').DataTable()
  
    $('#test-table thead tr th').each(function(i, e) {
      $(this).append('&lt;button id="test-button" style="margin-left: 5px; margin-right: 5px;"&gt;Test Button&lt;/button&gt;')
    })
  
    $('body').on('click', '#test-button', function(e) {
      alert('test')
      e.stopPropagation()
    })
  
  })</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/&gt;
  &lt;link href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css" rel="stylesheet"/&gt;
  
  &lt;script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"&gt;&lt;/script&gt;
  
  
  &lt;table id="test-table" class="table table-striped table-bordered"&gt;
    &lt;thead&gt;
      &lt;th&gt;Name&lt;/th&gt;
      &lt;th&gt;Description&lt;/th&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;a&lt;/td&gt;
        &lt;td&gt;a&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;b&lt;/td&gt;
        &lt;td&gt;b&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>