0

I am trying to create my own greasemonkey script for my favorite directory listing site :)

The thing is not everything it list is beneficial to me, I inspected the website code and as it seems, each entry is under

Now, and as it seems, I am only interested with those which have this format:

<tr class="project-description">
<td colspan="6">
    <div class="project-desc-inner">
        <div class="project-synopsis">
            <p class="trunk8">This is an entry</p>
        </div>
        <div class="project-verification">
            <span class="verfied-badge"> <~~~~~~~~~~ THIS SPAN
                <span class="currency-symbol">$</span>
                <span class="icon-tick"></span>
                Verified
            </span>
        </div>
        <div class="project-actions">
            <a href="#">
                <button class="btn">LOL</button>
            </a>
        </div>
    </div>
</td>
</tr>

As you can see, the existence of <span class="verfied-badge"> triggers it.

I also wish that the javascript process this after the page loads, because the site populates the table via javascript too.

I know I haven't done in my problem yet, but if somebody can just provide an example that can lead me, that is enough.

Thank you very much!

NilsH
  • 13,705
  • 4
  • 41
  • 59
The Wolf
  • 195
  • 3
  • 16
  • Next time be careful about stating correct languages especially in title, because **Java ≠ Javascript** in any way shape or form. Unless you're doing a string matching of *Java* in string *Javascript*. In that case you'll get a match. ;) – Robert Koritnik Feb 23 '15 at 08:02

2 Answers2

3
$(document).ready(function(){
    $("tr.project-details").each(function(){
       var self = $(this);
       if(self.find("span.verfied-badge").length==0)
           self.remove();
    });

});
void
  • 36,090
  • 8
  • 62
  • 107
  • 2
    +1, but there's an optimization for this: if you'd put matching TRs in a separate jQuery set and call a single `remove` on the set after you'd collect them all in iteration function. – Robert Koritnik Feb 23 '15 at 08:05
  • 1
    @void if I',m interested only with `` should i replace: `$("tr").each(function(){` with `$("tr.project-details").each(function(){` ? Thanks! – The Wolf Feb 23 '15 at 08:22
  • @void can you please tell me what specifically does `self.remove();`, it seems working but I do not think it is targetting the right `` playing with `self.remove();` I realize that it removes all the `` even those that i want :( – The Wolf Feb 23 '15 at 08:47
  • @RobertKoritnik I think that's what i need, can you provide an example? – The Wolf Feb 23 '15 at 09:42
1

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();
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404