Delete table without id using jquery

I have the following dynamically generated table on a page along with other tables on a page. I need to delete this table that does not have an identifier. There is one of two ways that I can think of to target a table for deletion, since they never change.

Under class = "matching_results_text" or under the text "You are here"

I just don’t know how to do it.

I tried $ ("table"). remove (": contains ('You are here:')"); but it didn’t work.

<table width="100%" border="0" cellspacing="0" cellpadding="5">
          <tr> 
            <td>        
                <b>You are here: <a href="http://www.test.com">Home</a> &gt; <a href="http://www.test.com/Ignition-Controls-s/30.htm" title="Ignition Controls">Ignition Controls</a></b>
<div class="matching_results_text">We found 10 results matching your criteria.</div>

 </td>
          </tr>
        </table>
+3
source share
3 answers

: , div.matching_results_text a[title=Ignition Controls], , .

, , , HTML. , .


jQuery .closest() , , .

    // Starting point is the class name
$('table div.matching_results_text').closest('table').remove();

    // Starting point is the <a> element with the title Ignition Controls
$('table a[title=Ignition Controls]').closest('table').remove();

, , :contains() .closest().

    // Starting point is the <b> element that contains "You are here"
$('table b:contains(You are here)').closest('table').remove();

http://api.jquery.com/closest/

, () 3- , .

     // Get the third table on the page
$('table:eq(2)').remove();

http://api.jquery.com/eq-selector/

+2
$("table").each(function() {
    var thisTable = $(this);
    if($(this).children().is(":contains('You are here')")) {
        thisTable.remove();
    }
});
+2

A simpler way:

$("table:contains('You are here')").remove();
+1
source

Source: https://habr.com/ru/post/1752968/


All Articles