Edit in JSFiddle

//Create element
var elem = document.createElement("div");

// Make the element fully transparent.
elem.style.opacity = 0;

//Force layout to be recalculated. Transition works only when one of the following is uncommented

//window.getComputedStyle(elem).opacity; //Works in Chrome, FF

//var c = elem.clientHeight; //Works in Chrome, FF

/*setTimeout(function() { //Works in Chrome, but not in FF
    elem.style.opacity = 1;
}, 0);*/

// Fade it in.
elem.style.opacity = 1;
div {
    background-color: black;
    display: block;
    transition: opacity 2s;