SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mozilla equivalent for IE's removeNode()?

    does anyone have an equivalent for IE's removeNode([true/false]) method?

    I think it's possible to use removeChildNode() or something like that I guess I'll look into that.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  2. #2
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using the following code works in both:
    Code:
    if (node.parentNode)
       node.parentNode.removeChild(node);
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  3. #3
    SitePoint Member fidel's Avatar
    Join Date
    Aug 2003
    Location
    harrisburg pa
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i love when people answer their own questions
    </spam>

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should emulate removeNode for Mozilla, but when I tested it, it only removed the node(s) for a split second. Anyone see what's wrong?
    Code:
    if ( window.Node )
    Node.prototype.removeNode = function( removeChildren )
    {
    	var self = this;
    	if ( Boolean( removeChildren ) )
    	{
    		return this.parentNode.removeChild( self );
    	}
    	else
    	{
    		var range = document.createRange();
    		range.selectNodeContents( self );
    		return this.parentNode.replaceChild( range.extractContents(), self );		
    	}
    }
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it to work!
    Code:
    <html>
    <head>
    <script>
    function removeThatNode( id, rc )
    {
    	var node = document.getElementById( id );
    	document.getElementById( 'target' ).appendChild( node.removeNode( rc ) );
    }
    if ( window.Node )
    Node.prototype.removeNode = function( removeChildren )
    {
    	var self = this;
    	if ( Boolean( removeChildren ) )
    	{
    		return this.parentNode.removeChild( self );
    	}
    	else
    	{
    		var range = document.createRange();
    		range.selectNodeContents( self );
    		return this.parentNode.replaceChild( range.extractContents(), self );
    	}
    }
    </script>
    </head>
    <body>
    	<button onclick="removeThatNode('tester')">Remove Node Only</button>
    	<br />
    	<button onclick="removeThatNode('tester',true)">Remove Node and Children</button>
    	<div id="tester" style="background-color: #EEE; border: 1px solid red">
    		<p>para</p>
    		<p>para</p>
    		<p>para</p>
    	</div>
    	<div id="target" style="border: 1px solid black">
    		Remove content will appear here
    	</div>
    </body>
    </html>
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've always thought that I was pretty confident using the DOM, be it whatever language though Bettle you really do show how to make use the DOM

    I'll be sure to keep that in mind if I run into Javascript issues at a later date with the DOM

  7. #7
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe, thanks. I guess I gotta do something to earn this Guru badge
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

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