Saturday, 27 May 2023

Show/Hide Multiple Divs with Jquery/Hide show div,elements on click in javascript/jQuery Hide Show

 <!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<title></title>


<style type="text/css">

body{

width: 100%;;

height: 100%;

background-color: #eee;

}

.menu{

margin: 5% 12%;

background: transparent;


}


a , #showall{

display: inline-block;

margin: 0 1%;

padding: 3%;

border-radius: 11%;

-webkit-box-shadow: 0 3px 12px 3px rgba(0, 0, 0, 0.2);

-moz-box-shadow: 0 3px 12px 3px rgba(0, 0, 0, 0.2);

box-shadow: 0 3px 12px 3px rgba(0, 0, 0, 0.2);

}

a:nth-child(1){

background-color: red; cursor: pointer; color: #fff;

}

a:nth-child(2){

background-color: green; cursor: pointer; color: #fff;

}

a:nth-child(3){

background-color: blue; cursor: pointer; color: #fff;

}

a:nth-child(4){

background-color: yellow; cursor: pointer; color: #fff;

}

.target_box{

margin: 6% 10%;

background: transparent;

}


</style>

</head>

<body>


<div class="menu">

<a id="showall">All</a>

<a class="Single" target="1">One</a>

<a class="Single" target="2">Two</a>

<a class="Single" target="3">Three</a>

</div>


<section class="target_box">

<div id="div1" class="target">Content one</div>

<div id="div2" class="target">Content two</div>

<div id="div3" class="target">Content three</div>

</section>



<script type="text/javascript">

jQuery(function(){

jQuery('#showall').click(function(){


jQuery('.target').show();

});

jQuery('.Single').click(function(){

jQuery('.target').hide();

jQuery('#div'+$(this).attr('target')).show();

});

});



</script>


</body>

</html>



No comments:

Post a Comment

The 10 best websites you've probably never heard & you should have to visit !

1.   codepen.io/akm2/full/rHIsa       Start having fun with gravity and say goodbye to your evening. And your job. 2.   co...