Question: How can I implement [prepend](http://api.jquery.com/prepend/) and [append](http://api.jquery.com/append/) with regular JavaScript without using jQuery?

Answer: 
In order to simplify your life you can extend the `HTMLElement` object. It might not work for older browsers, but definitely makes your life easier:

```
HTMLElement = typeof(HTMLElement) != 'undefined' ? HTMLElement : Element;

HTMLElement.prototype.prepend = function(element) {
    if (this.firstChild) {
        return this.insertBefore(element, this.firstChild);
    } else {
        return this.appendChild(element);
    }
};

```

So next time you can do this:

```
document.getElementById('container').prepend(document.getElementById('block'));
// or
var element = document.getElementById('anotherElement');
document.body.prepend(div);

```
This is not best way to do it but if anyone wants to insert an element before everything, here is a way.

```
var newElement = document.createElement("div");
var element = document.getElementById("targetelement");
element.innerHTML = '<div style="display:none !important;"></div>' + element.innerHTML;
var referanceElement = element.children[0];
element.insertBefore(newElement,referanceElement);
element.removeChild(referanceElement);

```