Is it possible for a Greasemonkey script to delete one row which has a null class (<tr class="" ...>
)?
The problem is that inside a <tbody>
tag there are two rows with a null class.
The row to be deleted is the first one.
<table id="sort_table" class="tablesorter">
<thead>
<tr>
<th class="blacktext timesroman_italic">This</th>
<th class="blacktext timesroman_italic">is a</th>
<th class="blacktext timesroman_italic">header</th>
<th class="blacktext timesroman_italic">row</th>
</tr>
</thead>
<tbody>
<!-- I WOULD LIKE TO DELETE FROM HERE -->
<tr class="" valign="middle">
<td class="bluetext timesroman align_middle">First</td>
<td class="bluetext timesroman align_middle">blank</td>
<td class="bluetext timesroman align_middle">class</td>
<td class="bluetext timesroman align_middle">row</td>
</tr>
<!-- TO HERE -->
<!-- BUT NOT FROM HERE -->
<tr class="" valign="middle">
<td class="bluetext timesroman align_middle">second</td>
<td class="bluetext timesroman align_middle">blank</td>
<td class="bluetext timesroman align_middle">class</td>
<td class="bluetext timesroman align_middle">row</td>
</tr>
<tr class="someclass" valign="middle">
<td class="bluetext timesroman align_middle">I gots</td>
<td class="bluetext timesroman align_middle">me</td>
<td class="bluetext timesroman align_middle">some</td>
<td class="bluetext timesroman align_middle">class</td>
</tr>
<tr valign="middle">
<td class="bluetext timesroman align_middle">no</td>
<td class="bluetext timesroman align_middle">class</td>
<td class="bluetext timesroman align_middle">attribute</td>
<td class="bluetext timesroman align_middle">row</td>
</tr>
<!-- TO HERE -->
</tbody>
</table>
I would like to delete the first "blank class" row. Like this:
Here's the pseudo-code I came up with but how do I do that in a script? :
Use jQuery and you can do it with one line of code:
$('#sort_table tbody tr:not([class!=""]):first').remove ();
See "Select elements without any class".
The complete Greasemonkey script would be like this:
// ==UserScript==
// @name _Remove the first body row that ain't got no class
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
$('#sort_table tbody tr:not([class!=""]):first').remove ();