Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Thanked 0 Times in 0 Posts

    JS to remove TR attributes

    Hi Guys,

    I'm new at JS.
    I need to remove TR elements from parent table but the problem is there are no table ID/Name

    Is it possible to perform it?
    Please see attach - i need remove red marked block... what scrip i have to use if i will put it to the green block?
    Thank you.
    Attached Thumbnails Attached Thumbnails -removetr-png  

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 Posts
    Despite the similar sounding names, Java is not the same as Javascript.
    Moving from Java forum to Javascript forum.
    DOM manipulation should include removal of child nodes, the JS people can give you more help with that.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  3. #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,947 Times in 4,908 Posts
    Assuming that, indeed, there is only one
        <td id="TopCell" ... >
    on that page (as indeed there should be, since id's should be unique) and assuming that you want to remove the second and third <tr>s from that enclosed <table>, then *removing* the rows is easy.

    *MOVING* the rows to the green-marked <div> is not so easy.

    Does that <div> already contain a <table>???

    If not, we would have to create a <table> inside the <div> to put the <tr> rows into.

    It would help if you would show that <div>'s contents, expanded out. At least one level.


    But it is clear that this page is being generated by ASP.NET. Wouldn't it be easier to change the ASP.NET code to do this, rather than trying to do it with JavaScript??
    Be yourself. No one else is as qualified.

  4. #4
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Splendora, Texas, United States of America
    Thanked 317 Times in 311 Posts
    Theoretically, the following code should do what you want. Unfortunately, I can't confirm that since it hasn't been tested since you didn't supply your source code nor is your request 100% clear due to your use of incorrect grammar and the issue noted by Old Pedant.

    Additionally, the code would have been simpler had I been able to see the entire ID of the div element. It's only partially visible in the reference image.

    var TopCell = document.getElementById("TopCell");
    if (typeof TopCell.firstElementChild !== "undefined" && typeof TopCell.lastElementChild !== "undefined") {
        // W3C DOM3 Core + W3C Element Traversal Method
        var table_element = TopCell.firstElementChild.cloneNode(true);
        var tbody_element = table_element.firstElementChild;
        div_element = document.getElementById("MSOZoneCell_WebPartWPQ5").firstElementChild.firstElementChild.firstElementChild.firstElementChild.firstElementChild;
    else if (typeof TopCell.getElementsByTagNameNS === "function") {
        // W3C DOM3 Core Method
        // Namespace‐Aware
        var XHTML_NS = "http://www.w3.org/1999/xhtml";
        var table_element = TopCell.getElementsByTagNameNS(XHTML_NS, "table").item(0).cloneNode(true);
        var tbody_element = table_element.getElementsByTagNameNS(XHTML_NS, "tbody").item(0);
        tbody_element.removeChild(tbody_element.getElementsByTagNameNS(XHTML_NS, "tr").item(0));
        div_element = document.getElementById("MSOZoneCell_WebPartWPQ5").getElementsByTagNameNS(XHTML_NS, "div").item(0);
    else {
        // W3C DOM3 Core Method
        // Not Namespace‐Aware
        var table_element = TopCell.getElementsByTagName("table").item(0).cloneNode(true);
        var tbody_element = table_element.getElementsByTagName("tbody").item(0);
        div_element = document.getElementById("MSOZoneCell_WebPartWPQ5").getElementsByTagName("div").item(0);
    For every complex problem, there is an answer that is clear, simple, and wrong.

    CSS Specifications


Posting Permissions

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