Edit in JSFiddle

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

// 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;
    height:100px;
    width:100px;
    transition: opacity 2s;
}