removing complete table row without specefic class

Subscribe to removing complete table row without specefic class 9 posts, 6 voices

 
pein Scriptwright Hi, i want to remove all table rows with this code inside
 |span class="PhorumListSubjPrefix">Sticky: |/span> 
code here:
<tr>
      <td class="PhorumTableRowAlt">
                 Sticky:                         rheingrillen am 8.3. cool

         NEU           Seiten: 123              </td>
              <td class="PhorumTableRowAlt">564 </td>
            <td class="PhorumTableRowAlt">57 </td>

      <td class="PhorumTableRowAlt">der-gio </td>
      <td class="PhorumTableRowAlt PhorumSmallFont">
        07.03.08 16:42 
Letzter Beitrag von gismoundbonny </td> </tr>
I tried alot. Regex, ... But i dont get it.
var ad = $x("//span");
var i = 0;
for(i;i<ad.length;i++)
 ad[i].parentNode.removeChild(ad[i]);
?! Can you please help me :) Thx
 
no0n Scriptwright

Well you could do it with a more sophisticated Xpath expression which I don't have the time to write right now. But it would involve spans containing that class with TR ancestors.

This is hackish but I think would work if the structure is always the same...

ad[i].parentNode.parentNode.parentNode.removeChild(ad[i].parentNode.parentNode)) // ad's 3rd parent is the TR's parent, 2nd parent is the target TR

 
gollum Scriptwright

If the parent structure is TD > SPAN, then something like this should work

"//span[@classs='PhorumListSubjPrefix']/../.."

for each span with class of "blah" return the parents parent(TR)

var ads = document.evaluate("//span[@classs='PhorumListSubjPrefix']/../..", document, null, ORDERED_NODE_SNAPSHOT_TYPE, null);
for( var i = 0; i < ads.snapshotLength; i++ )
  if( ads.snapshotItem(i) && ads.snapshotItem(i) != 'undefined' ) // just in case we've already deleted this row
    ads.snapshotItem(i).parentNode.removeChild(ads.snapshotItem(i));

All the above was of the top of my head - but I think it's right :wink:

 
pein Scriptwright

Hi thx for your response.

But both dont work, it happens nothing.

It is possible that there is something missing?

You could test it on this Website www.busfreunde.de

Greetings

 
rainworm Scriptwright

what about something like;

all_tds = document.getElementsByTagName('td');
for (i=0;i<all_tds>
if (all_td[i].indexOf('class="PhorumListSubjPrefix">Sticky')>-1) {
all_tds[i].style.display = 'none';
}
}

 
gollum Scriptwright

Shouldn't have tried it off the top LOL.

This works....

// ==UserScript==
// @name           PhorumListSubjPrefix
// @namespace      http://userscripts.org/forums/1/topics/1927
// @description    remove rows containing span class 'PhorumListSubjPrefix'
// @include        http://www.busfreunde.de/list.php*
// ==/UserScript==

var ads = document.evaluate("//span[@class='PhorumListSubjPrefix']/ancestor::tr", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for( var i = 0; i < ads.snapshotLength; i++ )
  if( ads.snapshotItem(i) && ads.snapshotItem(i) != 'undefined' ) // looking at the site, this shouldn't happen - but...belts and braces
    ads.snapshotItem(i).parentNode.removeChild(ads.snapshotItem(i));

 
pein Scriptwright

Yeah. it works.

Thank you :)

 
Descriptor Scriptwright

I was going to correct you, but you got it!
I don't think ads.snapshotItem(i) should ever be undefined (no quotes) or else ads.snapshotLength would probably be 0 and the loop would never start.

 
Mindeye Scriptwright

And you don't need to check both ads.snapshotItem(i) and ads.snapshotItem(i) != 'undefined'. If ads.snapshotItem(i) === undefined, then ads.snapshotItem(i) would evaluate as false and Javascript would short-circuit the && expression