Use jQuery to find a <tr> that is after a line with a specific attribute in it

I don't know if the title of this post makes sense, but here is a sample of what I'm working with:

<tbody>
    <tr class="classRow" bgcolor="#EFE5D3" style="font-weight: bold;">
        <td width="35px"><a class="classEditLink" name="33" href="#">Edit</a></td>
        <td width="20px"><input type="checkbox" class="chkSelectToDelete" name="deleteClasses[]" value="33" /></td>
        <td>CLASS1234</td>
        <td>Class description</td>
    </tr>
    <tr class="classDocsRow noDocs">
        <td colspan="4">
            <strong>No documents are currently associated with this class.</strong>
        </td>
    </tr>
</tbody>

I need to delete the second line by finding it using the name attribute of the <td> <a>previous line. The psuedo code will look like

$('.classRow a[name="' + classID + '"]').parent().parent().next().remove()

I don’t know if this correct jQuery syntax is (like it doesn’t work, for example), but I hope you understand: The "starting point" of the selector is the name attribute of the tag <a>and I need to remove the next line. The tag name attribute <a>is the only unique attribute in this <tbody>on the page (not including the third and fourth <td>in this line, but you get the point).

/ jQuery ?

+3
6

:

$('tr:has(a[name="33"]) + tr').remove();

JQuery:

+6

, - :

$(".classRow a[name=" + className + "]").closest("tr").next().remove();

. .

0

$('.classRow a[name="' + classID + '"]').parents("tr").next().remove();

, , ,

0

, , ID:

0

, ... , . , , .

:

  • / /

, , - :

$('.classRow a[name="' + classID + '"]').parent('classRow').find('.classDocs').remove();
0

( HTML ):

$('.classRow a[name="' + classID + '"]')
    .closest('tr')
    .next()
    .remove();

, , " ", DOM:

$(function() {
    // the code snippet here
});
0

All Articles