javascript - jQuery Slide to right - and replacing HTML -
original html:
<div id="filler"> <h2 class="rankings-header">donor rankings <img src="<?php bloginfo('stylesheet_directory'); ?>/img/right_arrow.png" style="right:0; padding-left:10px; cursor:pointer;" id="dr_collapse"></h2> </div>
jquery:
jquery(document).ready(function($){ $("#dr_collapse").click(function(){ $("#rankings-list").toggle("slide",{direction:"right"},700); $("#filler" ).html( '<h2 class="rankings-header">donor rankings <img src="/wp-content/themes/ati/img/left_arrow.png" style="right:0; padding-left:10px; cursor:pointer;" id="dr_collapse"></h2>' ); }); });
for reason, when click image, slide happens...once. , changes arrow image. can inspect html , see changed html.
but when click again, nothing happens , no js errors thrown
any ideas?
it's because you're replacing html #filler
, dom element #dr_collapse
being re-created, losing click event.
instead of $().click()
, use event binder .on()
, in way doesn't depends on inner dom element:
jquery(document).ready(function($){ $("body").on("click", "#dr_collapse", function(){ $("#rankings-list").toggle("slide",{direction:"right"},700); $("#filler" ).html( '<h2 class="rankings-header">donor rankings <img src="/wp-content/themes/ati/img/left_arrow.png" style="right:0; padding-left:10px; cursor:pointer;" id="dr_collapse"></h2>' ); }); });
Comments
Post a Comment