javascript - Select multiple tr based on provided data attribute values -
i trying select rows have data-attribute id 1,2.. can specifying each row seperatly isn't best way of doing it, can put me in right direction please ?
<table id="etable"> <tr data-empid="a123" data-salary="120" data-status="drone"> <td>peter</td><td>vogel</td><td>principal</td> </tr> <tr data-empid="b456" data-salary="130" data-status="worker"> <td>jan</td><td>vogel</td><td>general manager</td> </tr> <tr data-empid="c789" data-salary="110" data-status="worker"> <td>jason</td><td>van de velde</td><td>company nurse</td> </tr> </table>
selector
var getfromwebservices = //getfromwebservices() //result lets assume a123; b456 $("#etable tr[data-empid='a123; b456']").hide(); // hide here example, want object rows matching ids
i want dynamic. want selector rows empid a123; b456 in specific case
fiddle
http://jsfiddle.net/k6sx2313/2/
edit
why not returning rows 1 one, http://jsfiddle.net/k6sx2313/10/
the attribute selector can deal 1 value @ time, need use 2 selectors, separated comma:
$("#etable tr[data-empid='a123'], #etable tr[data-empid='b456']").hide();
if looking value programmatically, put them in array use filter()
:
var values = [ 'a123', 'b456' ]; $('#etable tr').filter(function() { return $.inarray($(this).data('empid'), values) != -1; }).hide();
Comments
Post a Comment