jquery show hide div

In this example below you will see how to do a jquery show hide div with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by s16f, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright s16f ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>jquery show hide div</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div class="one"><img src="http://lorempixel.com/400/200/technics/3" /></div>
<div class="two"><img src="http://lorempixel.com/400/200/technics/2" /></div>
<div class="button1">button1</div>
<div class="button2">button2</div>
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/s16f/jquery-show-hide-div-dibqo */
.button1, .button2 {
   width: 60px;
  height: 30px;
}

.button1 {
  background: white;
  margin: 10px;
}
.button2 {
  background: black; 
  margin: 10px;
}

body {
  background: darkgrey;
  color: red;
}

/*Downloaded from https://www.codeseek.co/s16f/jquery-show-hide-div-dibqo */

//selector.hover( over, out )
$('.two').hide();
$(".button1").hover(function(){
    $('.two').show();
    $('.one').hide();
},function(){
    $('.two').hide();
    $('.one').show();
});

Comments