jquery - How do I modify this code to allow a different element to trigger the event? -
html
<div id="sidebar"> <ul> <li> <h2> header </h2> <ul> <li><a href="#">li3</a></li> <li><a href="#">li2</a></li> <li><a href="#">li3</a></li> </ul> </li> </ul> </div>
jquery
$(document).ready(function () { $('li').click(function () { if ($('ul', this).is(":hidden")) { $('ul', this).slidedown("slow"); } else { $('ul', this).slideup("slow"); } } ); });
i want slideup()
, slidedown()
reached if <h2>
clicked. currently, both called if <li>
clicked.
how can fix this?
$(document).ready(function () { $('h2').click(function () { $(this).next('ul').slidetoggle('slow'); }); });
Comments
Post a Comment