I need to filter through rows of a table using a drop-down box with jQuery. What I can't figure out how to do is how to relate the value of the options to the data-type of the table rows.
HTML:
<label for=filter>Type:</label>
<select id=filter>
<option value=all>All Steps</option>
<option value=standard>Standards</option>
<option value=review>Reviews</option>
</select>
<table id=table>
<tr id=one class=row data-type=standard>
<td>Standard</td>
</tr>
<tr id=one class=row data-type=review>
<td>Reviews</td>
</tr>
</table>
JS:
$(#filter).change(function () {
$(#table).find(data-type).each(function () {
if ($(this).text() != $(#filter).val())
$(this).hide();
else
$(this).parent().show();
if ($(#filter).val() == all)
$(this).show();
});
});
The jQuery here is just pieced together based off of what I've found so far by researching around. It's important that I leave the data-type attribute in the table rows.
I'm pretty new to jQuery, so anything helps!
Here's the Code Pen: http://codepen.io/aburnsworth/pen/XKzgqa?editors=1111