hide javascript element nobr

4

I have this

<tr>
        <td nowrap="true" valign="top" width="190px" class="ms-formlabel"><h3 class="ms-standardheader">
        <nobr>Estado</nobr>
</tr>

<tr>
...
...
...
</tr>

<tr>
...
...
...
</tr>

<tr>
...
...
...
</tr>

What I want is that the tr where the label <nobr> has value "Status" is hiding the tr completely

I'm trying

$("tr[nobr='Estado']").hide();  

But it does not do anything

How to filter by label and its value?

Thanks

    
asked by Paolo Frigenti 22.10.2018 в 12:18
source

2 answers

7

The CSS query tr[nobr='Estado'] means give me the tr elements that have the attribute nobr with the value 'Estado' .

That is, you are looking for something like

<tr nobr="Estado"> ... </tr>

What you should look for is elements <nobr> within <tr> whose text contains "Estado" :

$('tr nobr:contains("Estado")')

let nobr=$("tr td nobr:contains('Estado')");
nobr.parent().parent().hide(); // o nobr.closest('tr').hide()
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
  <td nowrap="true" valign="top" width="190px" class="ms-formlabel">
    <h3 class="ms-standardheader">
        <nobr>Estado</nobr>
    </h3>
  </td>
</tr>
</table>
    
answered by 22.10.2018 / 12:33
source
3

As a complement to the answer of @ pablo-lozano, you have the option to use .filter() to filter those elements that have the value "Status" (exclusively):

$("#tabla").find("tr").find("nobr").filter(function(index) {
    return $(this).text() === "Estado";
  }).closest("tr").hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="tabla">
    <tr>
        <td><h3>Otro td</h3></td>
        <td nowrap="true" valign="top" width="190px" class="ms-formlabel">
            <h3 class="ms-standardheader">
                <nobr>Estado</nobr>
        </td>
    </tr>

    <tr>
        <td nowrap="true" valign="top" width="190px" class="ms-formlabel">
            <h3 class="ms-standardheader">
                <nobr>Foo</nobr>
    </tr>

    <tr>
        <td nowrap="true" valign="top" width="190px" class="ms-formlabel">
            <h3 class="ms-standardheader">
                <nobr>Bar</nobr>
    </tr>

</table>

Edit

As @loisb says in your comenterio you can use the parent() or if you do not look for the closest("tr") as I have now.

    
answered by 22.10.2018 в 12:36