I'm looking to translate this code into pure javascript so I don't have to use jquery:
$('#msg').show(0).delay(5000).hide(0);
What would be the javascript equivalent?
You can use the following code:
document.getElementById("msg").style.display = 'block';
setTimeout(function () {
document.getElementById("msg").style.display = 'none';
}, 5000);
#msg {background: #f90; width: 50px; height: 50px;}
<div id="msg">
Hello
</div>
I have given the CSS for demo purposes to be clear.
An other version of Praveen code using opacity.
var p = document.getElementById('msg');
p.style.opacity = 1;
setTimeout(function() {
p.style.opacity = 0;
}, 5000)
hide is roughly equivalent to calling .css( "display", "none" ).visibility. 1. Opacity has less browser support than display. 2. Opacity doesn't remove the element from the view.