Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move HTML element

Tags:

How to move HTML element to another element. Note that, I don't mean moving element's position. Consider this HTML code:

<div id="target"></div> <span id="to_be_moved"></span> 

I want to move "to_be_moved" to "target" so "target" has child "to_be_moved" now. So the result should be like this:

<div id="target"><span id="to_be_moved"></span></div> 

I've searched in google (especially using prototype framework) but all I've got is moving position, not as I want. Thanks before.

like image 873
iroel Avatar asked Jul 28 '10 21:07

iroel


People also ask

How do I move HTML element from one div to another?

All you have to do is select the element(s) you want to move, then call an “adding” method such as append() , appendTo() or prepend() to add the selected elements to another parent element.

How do you change the position of text in HTML?

To set text alignment in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property text-align for the center, left and right alignment.

How do you move an element to the middle of the page in HTML?

In your HTML, you'd give the div a class name like "center." You can then use the class selector .center to style it with the margin, width, border, and padding properties.


1 Answers

document.getElementById('target').appendChild(  document.getElementById('to_be_moved') ) 
like image 112
meder omuraliev Avatar answered Sep 22 '22 05:09

meder omuraliev