function - jquery toggle() on DIV by hiding other div's -
i using following code toggle div clicking on block heading. need make respective div appear on click of respective block headings. div should toggle themselves.
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> { color:#c30; text-decoration:none; } #banner { width: 930px; background-color:#666; height: 500px; } #banner ul { list-style:none; padding: 40px; } #banner ul li { margin: 10px 0 0 0; } #banner ul li { display:inline-block; border:5px solid #fff; background-color:#fc9; padding:10px; font: bold italic 18px verdana; } .slidercontent { border:5px solid #fff; background-color:#fc9; padding:10px; min-height: 150px; display:none; margin-top:5px; } .slidercontent { padding:0 !important; border:none !important; } .slidercontent a.closebutton { background:url(icon_modal_close.png) no-repeat 0 0; float:right; height:30px; width:30px; text-indent:-999px; } </style> <script type="text/javascript" language="javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $('a.box').click(function(event){ event.preventdefault(); $(this).next('.slidercontent').toggle(function() { $('.slidercontent').not(this).hide(); }); }); $('.closebutton').click(function(){ $(this).parent().hide(); }); }); </script> </head> <body> <div id="banner"> <ul> <li> <a href="#" class="box">design</a> <div class="slidercontent"> <a class="closebutton" href="#">close</a> lorem ipsum doner </div> </li> <li> <a href="#" class="box">development</a> <div class="slidercontent"> <a class="closebutton" href="#">close</a> lorem ipsum doner </div> </li> <li> <a href="#" class="box">graphics</a> <div class="slidercontent"> <a class="closebutton" href="#">close</a> lorem ipsum doner </div> </li> </ul> </div> </body> </html>
now problem div hide() function. toggle function executes first hide() function comes picture. makes layout distorted @ time 2 div shown on screen moment.
it should div hide first current div appear.
please me on same.
thanks lokesh yadav
try this:
$(document).ready(function() { $('a.box').click(function(event){ event.preventdefault(); var slidercontent = $(this).next('.slidercontent'); $('.slidercontent').not(slidercontent).hide(); slidercontent.toggle(); }); $('.closebutton').click(function(){ $(this).parent().hide(); }); });
here jsfiddle : http://jsfiddle.net/jtssm/5/
Comments
Post a Comment