# prependChild instead of appendChild

**URL:** <https://forum.kirupa.com/t/prependchild-instead-of-appendchild/278969>\
**Category:** web dev\
**Created:** [January 8, 2009, 4:25am UTC](https://forum.kirupa.com/t/prependchild-instead-of-appendchild/278969 "2009-01-08T04:25:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [January 8, 2009, 4:25am UTC](https://forum.kirupa.com/t/prependchild-instead-of-appendchild/278969/1 "2009-01-08T04:25:11Z")

</div>

Let’s say I already have code to create DIV’s with the CSS _“float:left”_ property. I want to add these floating DIV’s to the beginning of the container DIV instead of to the end because there’s a _“clear:both”_ line break that will make the container expand as I insert new floating DIV’s.

```auto

<div id="container">
   <br class="clear" />
</div>

```

Is there such a function like this fake “prependChild” I made up?

```php

var container = document.getElementById("container");
cointainer.prependChild(floatDiv1);
cointainer.prependChild(floatDiv2);
cointainer.prependChild(floatDiv3);

```

Which will change the HTML to:

```auto

<div id="container">
   <div class="floatLeft"></div>
   <div class="floatLeft"></div>
   <div class="floatLeft"></div>
   <br class="clear" />
</div>

```
