Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to hide an image when website loads, but have a button that shows it

Tags:

jquery

I'm not sure why this isn't working, keep it simple.

I need it to be JQuery as well because this is kind of an exercise I need to do on JQuery

<script>
$(document).ready(function(){
    $(".kuva1").hide()
        });

$(document).ready(function(){
    $("button").click(function(){
        $("#kuva1").fadeIn(5000);
    });
});
</script>

<button type="button">Show Image</button>

<div id="div1">
<img class="kuva1" src="./kuvat/daisy.jpg" style="width:384px;height:216px;">
<div>
like image 806
J. Vesa Avatar asked Dec 01 '25 23:12

J. Vesa


1 Answers

Try to use . instead of # since you donot have id but class

$(document).ready(function(){
$("button").click(function(){
    $(".kuva1").fadeIn(5000);
});
});
like image 72
Prashant Avatar answered Dec 03 '25 14:12

Prashant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!