Reality-Torrent Reality-Torrent - 11 days ago 8
HTML Question

Hide <tr> based on ID

I have a page consisting of several

<div>
elements and each
<div>
element has several
<tr>
tags. These
<tr>
tags are added dynamically but all get a unique ID.

Now when the user picks a certain value from a dropdownbox I want to hide all the
<tr>
tags that does not match the users choice.

This allows me to get the ID of the option the user has chosen.

$('#groupDropDownBox option:selected').attr('id');


And this selects all the
<tr>
tags inside the
<div>
.

$('#reviewGroupsDiv tr')


Now how would I go about hiding all
<tr>
tags that does now have the ID that the user has selected?

Appreciate any assistance!

Answer

If you want to hide the <tr> with the selected ID, you simply select it by its id:

$(selectedId).hide()

If you want to hide everything BUT the selected ID, you can use the jQuery .not() selector to select all elements from a certain type without the one that has your desired ID:

$('tr').not(selectedId).hide()