Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts

    Question insert a new Node

    is there a quick mode to insert a new Node inside a Node (the new one will become a Node for all the Childs)?

    Ex I have

    <td>
    --childs here--
    </td>

    I need
    <td>
    <div>
    --childs here--
    </div>
    </td>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Well, nothing shorter than
    Code:
    var
        parent=td.appendChild(document.createElement('div'));
    if that's what you mean.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Nope, I tried, but the result is:

    I need
    <td>
    --childs here--
    <div>
    </div>
    </td>

    I need to nest all the parent's childs inside the new created element.

    I tried remove the childs, append the cteated element and append inside the removed childs but it wount work either. On one hand, the removeChild leaves unexpectable tags inside the parent (such as <br>) and in fact the variable is an array of objects and I am not sure how to concatenate array's elements if they are objects...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Well, this sounds like a simple fix, but I need to see some code for it.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Internet Explorer gets this wrong even though they claim to support everything here:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<head>
    		<title>46092</title>
    		<style type="text/css">
    			p	{
    				border:1px solid #f00;
    			}
    			div	{
    				border:1px solid #0f0;
    				padding:1em;
    			}
    		</style>
    	</head>
    	<body>
    		<div id="div">
    			<p>
    				Text
    			</p>
    		</div>
    	</body>
    	<script type="text/javascript">
    		var div = document.getElementById('div');
    		var new_div = document.createElement('div');
    
    		for(var i = 0; i < div.childNodes.length; i++)
    		{
    			new_div.appendChild(div.childNodes[i].cloneNode(true));
    		}
    		for(i = div.childNodes.length - 1; i > 0; i--)
    		{
    			div.removeChild(div.childNodes[i]);
    		}
    		div.appendChild(new_div);
    	</script>
    </html>

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by hemebond
    Code:
    		for(i = div.childNodes.length - 1; i > 0; i--)
    		{
    			div.removeChild(div.childNodes[i]);
    		}
    try this:

    Code:
    for(i = div.childNodes.length - 1; i >= 0; i--)
    *this message will self destruct in n-seconds*

  • #7
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Ah of course. Hmm. Why the heck did it work in Firefox?

    Ah got it. Gecko includes text nodes as child nodes. This means I was leaving in the very first child node, which in Firefox was just a text node of a tab. Internet Explorer ignores text nodes when referencing them through childNodes.

  • #8
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Internet Explorer ignores text nodes when referencing them through childNodes
    Not exactly. IE ignore text nodes as childNodes when their NodeValue is null.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #9
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    But a tab character isn't null. Stupid IE.

  • #10
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I wonder if it is more stupid than considering, as Moz does, the HTML "Tab space" as a valueable child

    free space(non-space)
    <td>
    </td>
    Is evaluated by Moz as a firstChild, but
    <td></td>
    it is not

    Seems an equivalent stupidity for me as well ...

    Probably when we all will start using <tag /> notation problem would be easier to handle.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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