SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: DOM move a node

  1. #1
    SitePoint Addict Php_penguin's Avatar
    Join Date
    Aug 2004
    Location
    Colwyn Bay, Wales, UK
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DOM move a node

    Hi there, been searching google for about an hour but found nothing really usefull.

    I want to move a node from its current position, wherever in the parent it may be, to the top of its parent node.

    so say i have:
    a very abbridged dictionary
    - abacus
    - banana
    - candle

    i might want to move "banana" to be above "abacus". I've seen plenty of things about deleting and removing nodes, but to clone and remove would seem a bit of a cludge. Is there anyone who acn help?

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You can just move it by using insertBefore on an existing node and inserting it elsewhere.

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    
    window.promote=function(node){
    	if(node.previousSibling){
    		pa= node.parentNode;
    		pa.insertBefore(node,pa.firstChild);
    	}
    	return node;
    }


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
  •