html - Update CSS using Javascript -
i'm using next javascript open , close div blocks faq style page. i'm trying li display cursor:pointer if there kid div below it.
<script type="text/javascript"> $(document).ready(function() { $('#faqs li').each(function() { var tis = $(this), state = false, answernext = tis.next('div').hide().css('height','auto').slideup(); answerall = $('#faqs').children('div').hide().css('height','auto').slideup(); tis.click(function() { state = !state; answerall.slideup(state); $('#faqs').children('li').removeclass('active'); answernext.slidetoggle(state); tis.addclass('active',state); }); }); }); </script>
how can add together class cursor:pointer li if kid div exists?
here html i'm using:
<div id="faqs"> <ul class="servicelist"> <div class="servicelisttitle">list title</div> <li>list item without div</li> <li>list item div</li> <div>this open when above li clicked</div> <li>list item without div</li> </ul>
you don't show much code, if have like
<ul id="faqs"> <li>no child</li> <li>child<div>something</div></li> <li>still no child</li> <li>with child<div>something else</div></li> </ul>
you can select kid divs, take parents (the li
s div
children):
$('#faqs > li > div').parent().css('cursor','pointer');
here's jsfiddle.
javascript html css
No comments:
Post a Comment