code-8
code-8

Reputation: 58632

update specific column of a specific row - jQuery

I have this jquery code

console.log($('#tr-' + notificationInstanceId));

return

n.fn.init [a#tr-fg, context: document, selector: "#tr-fg"]

It showed you that the select works.

Now, I want to update the 6th column of that row - so I did

$('#tr-' + notificationInstanceId).find('td').eq(6).hide;
$('#tr-' + notificationInstanceId).find('td:eq(1)').eq(6).hide;

nothing seems to work. What did I do wrong?

HTML

<tbody>

    <tr>
        <td>1</td>

        <td>
            <a href="/a/OS/iii/1?instanceId=OS&amp;ip=1.1.1.1&amp;port=8008&amp;h=509A4CDB9AB2&amp;nae=OS&amp;nodeName=B-Z" id="tr-OS">
                OS
            </a>
        </td>
        <td>2</td>

        <td>
            8.4 GB
        </td>

        <td> NA </td>
        <td class="state-OS">running</td>
        <td>

        </td>

    </tr>



    <tr>
        <td>2</td>

        <td>
            <a href="/a/bu-uu/iii/1?instanceId=bu-uu&amp;ip=1.1.1.1&amp;port=8008&amp;h=509A4CDB9AB2&amp;nae=bu-uu&amp;nodeName=B-Z" id="tr-bu-uu">
                bu-uu
            </a>
        </td>
        <td>0</td>

        <td>
            0.0 GB
        </td>

        <td> NA </td>
        <td class="state-bu-uu">not instantiated</td>
        <td>
        </td>

    </tr>



    <tr>
        <td>3</td>

        <td>
            <a href="/a/fg/iii/1?instanceId=fg&amp;ip=1.1.1.1&amp;port=8008&amp;h=509A4CDB9AB2&amp;nae=fg&amp;nodeName=B-Z" id="tr-fg">
                fg
            </a>
        </td>
        <td>0</td>

        <td>
            0.0 GB
        </td>

        <td> NA </td>
        <td class="state-fg">not instantiated</td>
        <td>

        </td>

    </tr>



</tbody>

Upvotes: 0

Views: 232

Answers (1)

Barmar
Barmar

Reputation: 780688

.find() is for finding descendants of an element. The 6th column of the table is not a descendant of #tr-fortiGate. You need to go up to the containing <tr>, then find the desired child of that.

Using a class selector is a little better than hard-coding a column number, IMHO. It allows you to rearrange the columns without having to update the code.

$("#tr-" + notificationIsntanceId).closest("tr").children("td[class^=state-]")

Upvotes: 2

Related Questions