JavaScript/jQuery hide divs one by one -
i'm playing jquery. want click "hide me now" button div
elements fade out 1 after other. how do that? got fiddle here: https://jsfiddle.net/um7ctpnj/1/
index.html
<!doctype html> <head> <title>button show</title> <link rel="stylesheet" href="stylesheet.css"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> </head> <body> <button id="show" type="button" class="btn btn-primary">click me!</button> <button id="hide" type="button" class="btn btn-primary">hide me now!</button> <div id="one">1</div> <div id="two">2</div> <div id="three">3</div> <script src="javascript.js"></script> </body> </html>
javascript.js
$(document).ready(function (){ $('#show').click(function(){ $( "div:hidden:first" ).fadein( "slow" ); }); $('#hide').click(function(){ $( "div" ).fadeout("fast"); }); });
stylesheet.css
div { margin: 3px; width: 80px; display: none; height: 80px; float: left; } #one { background: #f00; } #two { background: #0f0; } #three { background: #00f; }
$('#hide').click(function(){ $( "div" ).fadeout("fast"); });
here div fadeout because of using div
selector instead use div:visible:last
hide 1 one.
$('#hide').click(function(){ $( "div:visible:last" ).fadeout("fast"); });
check working fiddle
Comments
Post a Comment