Hiding images while clicking on a button using jQuery




Live Preview:





  




Did you see that some websites are hiding and showing images when we click on some links or buttons. Do you know how it works. Here is the solution for your confusion. Here I created 2 buttons naming hide me and show me to hide the picture and to show the picture when clicked on that button.The working of this program is completely built on jQuery which is simple and easy to learn.


Here I used two jQuery function show() and hide() to hide and view the images. You can use as many images as you want. The $(document).ready(function) is used here to load the function only when the entire document is loaded. The jQuery will work only if we have the Google or Microsoft cdn which is placed on the source code of the script tag.


Video Preview:


See how do the hide and show function works in this video. The video is uploaded in the youtube channel 'How To'. Subscribe the channel to get tuned.The code of the given program is given below.

Code:

<html>
<head>
<style>
.clickk
{
border:2px solid black;
}
</style>

<div class="clickk">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>


<script>
$(document).ready(function(){
  $("#bbutton").click(function(){
    $("img").hide(750);
  });
});

$(document).ready(function(){
  $("#bbbutton").click(function(){
    $("img").show(750);
  });
});
</script>
</head>
<body>

<br />
<center>
<br />

<img border="0" data-original-height="569" data-original-width="1080" height="168" id="im" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhEH7Nj1cfIZQyOndoH1gGEz28bL0vzn6smwChwJGQQLUOU2Kd1EUSMKn4QGsdX0D8lfR13KxxkogzzxWSwmvOLCUK75On3BFQHJyOlKojyvE8wwgWA5SjjtyIYsnO5w9qwAKxr_sTSw6G4/s320/IMG_20190619_185038.jpg" width="320" />
<br />
<br />

<button id="bbutton">hide me</button>&nbsp;&nbsp;
<button id="bbbutton">show me</button>
<br />

<br />
<img border="0" data-original-height="426" data-original-width="640" height="213" id="im" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNQA7VCZogJiehm4zC3QNtQ26DOCW0baoWQk5Og_c18ejdAHzj3c2v3Y32TzwEOpRVCZnX5XjuTOi1dNJi_RQnmDx2ZtGmRNdFt6kK92nhGDULZAYDW1p41vyhGMwZM3R3W5JWyK0qk1n-/s320/images+%25281%2529.jpeg" width="320" />
<br />
<br />

</center>
</div>
</body>
</html>



Thank You...Stay Updated

Comments

Post a Comment

Popular posts from this blog

Node.js Cheat Sheet

Codeigniter ! Simple But Powerful

Introducing Cloudflare Pages ⚡