accordian with JQuery click, slideUp and slideDown -
i want disply 3 divs on page (accordian jquery click, slideup , slidedown functions)
but want 1 of divs "open" when page loads.
here code,
$(document).ready(function() { $('.title').click(function() { $('.title').removeclass('on'); $('.content').slideup('normal'); if($(this).next().is(':hidden') == true) { $(this).addclass('on'); $(this).next().slidedown('normal'); } }); });
css, .title { padding-left:15px; height:17px; background: url(images/arrow-toggle.png) 0 3px no-repeat !important; cursor:pointer; margin-bottom:10px; color:#104675; } .on { background: url(images/arrow-toggle.png) 0 -12px no-repeat !important; } .content { display:none; background-color:#f4f2f3; border: #cccccc 1px solid; padding: 10px; margin-bottom:10px; } -------- html, <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="css/dropdownwitharrows.css" type="text/css" media="screen" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> <script src="js/dropdownwitharrows.js" type="text/javascript"></script> </head> <body> <div class="title"><h1>header one</h1></div> <div class="content"><p>content here..bla bla bla</p></div> </body>
try
$(document).ready(function() { var $titles = $('.title'), $contents = $('.content'); $titles.click(function() { var $acts = $titles.filter('.on').removeclass('on'); $acts.next().finish().slideup('normal'); if($(this).next().is(':hidden') == true) { $(this).addclass('on'); $(this).next().finish().slidedown('normal'); } }).first().click(); });
demo: fiddle
Comments
Post a Comment