Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-17-2010, 07:46 AM   PM User | #1
455047@mail.ru
New to the CF scene

 
Join Date: Jul 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
455047@mail.ru is an unknown quantity at this point
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
Click image for larger version

Name:	removeTR.png
Views:	51
Size:	43.0 KB
ID:	8711  
455047@mail.ru is offline   Reply With Quote
Old 07-17-2010, 03:30 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 07-17-2010, 10:25 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Assuming that, indeed, there is only one
Code:
    <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??
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 07-18-2010, 08:09 AM   PM User | #4
Arbitrator
Senior Coder

 
Arbitrator's Avatar
 
Join Date: Mar 2006
Location: Splendora, Texas, United States of America
Posts: 2,906
Thanks: 5
Thanked 191 Times in 188 Posts
Arbitrator is on a distinguished road
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.

Code:
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;
    tbody_element.removeChild(tbody_element.firstElementChild);
    div_element = document.getElementById("MSOZoneCell_WebPartWPQ5").firstElementChild.firstElementChild.firstElementChild.firstElementChild.firstElementChild;
    div_element.appendChild(table_element);
}
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);
    div_element.appendChild(table_element);
}
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);
    tbody_element.removeChild(tbody_element.getElementsByTagName("tr").item(0));
    div_element = document.getElementById("MSOZoneCell_WebPartWPQ5").getElementsByTagName("div").item(0);
    div_element.appendChild(table_element);
}
__________________
Please for the love of god stop making IE. You current "browser"s cause me to cry every day. —Phil *
Arbitrator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:02 PM.


Advertisement
Log in to turn off these ads.