First of all, give the table id.
<table id="departures">
Save all the necessary lines in the jQuery object and only those that are inside #departures.
var $departures = $("#departures");
var $rows = $("tr[id^=row_]", $departures);
This way jQuery will not go through the DOM every time you execute the function, because it will be stored inside the object.
Then use your code as usual
var sClient = $(this).attr("id").substring(6);
sClient = sClient.substring(0,sClient.indexOf("_"));
When replacing the last line with
$rows.not("tr[id^=row_" + sClient + "]", $departures).remove();
source
share