jquery - appending html into the dom, then when i use an on(click) function I get $this is undefined -
i have list of stuff, want insert options after dom loaded.
$(document).ready( function() { //add sharing stages var $stage = $('.stage > h3'), $stagesharebtn = $('.stage h3'); $stage.append('<i class="fa fa-share"></i>'); $stage.after('<div class="share-stage"><a href="#"><i class="fa fa-facebook"></i></a><a href="#"><i class="fa fa-twitter"></i></a><a href="#"><i class="fa fa-google-plus"></i></a></div>').end; $stage.on( 'click', function(e){ e.preventdefault(); $this.next('.share-stage').toggleclass('active'); }); });
the append , after worked fine, jquery hooked correctly. if leave $this off function, works triggers on page.
Comments
Post a Comment