I am trying to make a div disappear with javascript. It just doesn't work. What am I doing wrong?
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
document.getElementById("des").style.visibility = "hidden";
</script>
<div id="des">
Text.
<a href="">link</a>
</div>
You are running the script before the DOM has loaded.
If you put the script after the div, it works
Try and throw a document ready around your code.
And if you are loading jquery you can just do $('#des').css('visibility', 'hidden');
or $('#des').hide()
<script type="text/javascript">
$(document).ready(function(){
$('#des').css('visibility', 'hidden');
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With