javascript on page load check if a span (under <tr>) with a specific class exist, if does not exist remove the entire <tr>

蹲街弑〆低调 提交于 2019-12-02 11:22:30
$(document).ready(function(){
    $("tr.project-details").each(function(){
       var self = $(this);
       if(self.find("span.verfied-badge").length==0)
           self.remove();
    });

});

Filtered selector that calls .remove only once

Since there're other span elements within TR that are unrelated to the problem it's not possible to write a pure CSS filter selector string (so we could either use .has) to sufficiently filter elements. but instead of removing each table row individually we filter them first and remove them all at once.

$("tr.project-description").filter(function() {
    return !$("span.verfied-badge", this).length;
}).remove();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!