Steve Steve - 1 year ago 74
jQuery Question

datatable search by clicking dynamically created element

I am trying to search for the band in the datatables by clicking on the band (


@foreach($bands as $band)
<td class="bg-info">
<div class="search"><a href="">{{$band->name}}</a></div>
<td class="bg-info">

I'm searching in table with id featured. i.e.

$(document).on('click','.search', function(e) {
var search = $(this).val();;

But, while i click on any band i got MethodNotAllowed exception.

Answer Source

Your logic to achieve this isn't quite right. You need to call search() on the DataTable itself, not on a jQuery object (or a string as in your original example). Then the value of the search term is coming from the text of the a element within the .search div. Try this:

var dt = $('#yourTable').DataTable();

$(document).on('click', '.search a', function(e) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download