I'm trying to hide an element using jQuery, but I think I did something wrong. Please take a look at my code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type = "text/javascript">
$(function(){
function hide(id) {
$("#"+id).hide();
}
});
hide("test");
</script>
<div id = "test"> Hello </div>
Sushil is right, but also, your "hide" function should be outside the $() function and the call to it goes on the inside. The whole thing looks like this:
function hide(id) {
$("#" + id).hide();
}
$(function(){
hide("test");
});
Putting the hide() function inside of the $() makes it so you can only call it from inside of the $(). So, put it on the outside, and then you can call it from anywhere, including, from inside the $() part.
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