I’ve been trying to solve this but no luck so far. I have the following HTML…
<table id="datatable">
<tbody id="datarows">
<tr id="row1" class="datarow" style="display: table-row;">...</tr>
<tr></tr>
<tr id="row2" class="datarow" style="display: table-row;">...</tr>
<tr></tr>
<tr id="row3" class="datarow" style="display: table-row;">...</tr>
<tr></tr>
<tr id="row4" class="datarow">...</tr>
<tr></tr>
<tr id="row5" class="datarow">...</tr>
<tr></tr>
<tr id="row6" class="datarow">...</tr>
</tbody>
</table>
Why does my JavaScript want to target row1, when it’s supposed to target row4? Or perhaps there is an intuitive to say, add the style attribute only to the next #row<number>
that doesn’t have it…? am I close?
window.jQuery("#datatable #datarows tr[id^='row']:not([style='display: table-row']:first)").css({"display":"table-row"});
2
Answers
:first
should afternot()
paranthesis not after theattribute
bracketsI think this will work:
It should get match all the tr’s with "row" in the id within the tbody "datarows" of the table "datatable" that have no style attribute. It will filter those tr’s for the first one and apply your "display: table-row" style.