javascript - How hide/visible element in accordion -
i want when accordion element visible span , img element display , when invisible not displayed. in fact user click on 1 of element display img , span add , when user slide toggle span , img hide.
$("#accordion > li > div").click(function(){ if(false == $(this).next().is(':visible')) { $('#accordion ul').slideup(300); } $(this).next().slidetoggle(300); }); $('#accordion ul:eq(0)').show();
#accordion { list-style: none; padding: 0 0 0 0; width: 170px; } #accordion div { display: block; background-color: #ff9927; font-weight: bold; margin: 1px; cursor: pointer; padding: 5 5 5 7px; } #accordion ul { list-style: none; padding: 0 0 0 0; } #accordion ul{ display: none; } #accordion ul li { font-weight: normal; cursor: auto; padding: 0 0 0 7px; } #accordion { text-decoration: none; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul id="accordion"> <li> <div>sports <img src='' width='25' height='25'> <br><span>#20</span></div> <ul> <li><a href="#">golf</a></li> </ul> </li> <li><div>technology<img src='' width='25' height='25'> <br><span>#20</span></div> <ul> <li><a href="#">iphone</a></li> </ul> </li> </ul>
what interpret looking this
#accordion { list-style: none; padding: 0 0 0 0; width: 170px; } #accordion div { display: block; background-color: #ff9927; font-weight: bold; margin: 1px; cursor: pointer; padding: 5 5 5 7px; } #accordion ul { list-style: none; padding: 0 0 0 0; } #accordion ul{ display: none; } #accordion ul li { font-weight: normal; cursor: auto; padding: 0 0 0 7px; } #accordion { text-decoration: none; } #accordion > li > div>img{ display:none; } $("#accordion > li > div").click(function(){ if(false == $(this).next().is(':visible')) { $(this).children('img').show(); $('#accordion ul').slideup(300); } else { $(this).children('img').hide(); } $(this).next().slidetoggle(300); }); $('#accordion ul:eq(0)').show(); $('#accordion > li:first-child > div>img').show(); <ul id="accordion"> <li> <div>sports <img src='' width='25' height='25'> <br><span>#20</span></div> <ul> <li><a href="#">golf</a></li> </ul> </li> <li><div>technology<img src='' width='25' height='25'> <br><span>#20</span></div> <ul> <li><a href="#">iphone</a></li> </ul> </li> </ul>
Comments
Post a Comment