Login   Register  
Icontem

Rather a lot of code for a simple move

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      Move image into another HTML element  >  All threads  >  Rather a lot of code for a simple move  >  (Un) Subscribe thread alerts  
Subject:Rather a lot of code for a simple move
Summary:Two one line image move commands
Messages:1
Author:Stephen Chapman
Date:2012-12-13 10:49:54
 

  1. Rather a lot of code for a simple move   Reply  
Picture of Stephen Chapman
Stephen Chapman
2012-12-13 10:49:54
You seem to be going about this the long way wit a whole lot more code than is needed for moving any element of a web page from one spot to another.

Assuming that the variable 'a' references your image - either already in the web page or created and waiting to be inserted and 'b' points to the element in the page you want to point it to then:

b.parentNode.insertBefore(a,b);

will insert the image immediately before the opening tag that 'b' points to and

b.appendChild(a);

will insert the image immediately before the closing tag of the element 'b' points to.

If the image was already in the page then either of those commands will remove it from where it was and insert it into the new location.

These commands will work for moving ANY element from one spot in the web page to another and not just images.