www.webdeveloper.com
Results 1 to 6 of 6

Thread: Delete rows through Javascript.

  1. #1
    Join Date
    Apr 2010
    Posts
    3

    Delete rows through Javascript.

    I need to create a userscript, which removes certain rows containing a particular text.
    1. The problem is that the site uses table class to identify tables, instead of id.
    2. How do I specify the condition that a cell of the row contains "0"

    Please tell me if the html source is required.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    var aObj=document.getElementsByTagName('td');
    var i=aObj.length; 
    while(i--) { 
        if(aObj[i].firstChild.data=='0') {
            var theRow = aObj[i].parentNode;
            theRow.parentNode.removeChild(theRow);
            }
        }
    You may need to target only specific tables
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Apr 2010
    Posts
    3
    I am completely a noob in this matter. Could you please tell me, how to target the table. It is identified by "class=lista"
    Also, the rows we have to delete are similar to this

    <tr>
    <td class="lista" align="left"><a href = ?????><td class="lista" align="center"><a href=???><img src=???></a></td>
    <td class="lista" align="center">some data</td>
    <td class="lista" align="center">some data</td>
    <td class="lista" align="center"><span style="color: red;">0</span></td> <td class="lista" align="center"><span style="color: red;">0</span></td> <td class="lista" align="center">---</td><td class="lista" align="center">&nbsp;</td><td class="lista" align="center">&nbsp;</td></tr>

    We have to delete the complete row based on the bold td.

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    You want to delete the row, including links, images and data?
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #5
    Join Date
    Apr 2010
    Posts
    3
    Yes, actually, this a list (Do not want to indulge in details), and I want to remove the results which have zero as data in one of the cell (division)

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    var aObj=document.getElementsByTagName('td');
    var i=aObj.length; 
    while(i--) { 
        if(aObj[i].className=='lista' && aObj[i].firstChild.nodeName.toUpperCase()=='SPAN' && aObj[i].firstChild.firstChild.data=='0') {
            var theRow = aObj[i].parentNode;
            theRow.parentNode.removeChild(theRow);
            }
        }
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles