Skip to content

Instantly share code, notes, and snippets.

@joshdcomp
Created January 26, 2016 21:20
Show Gist options
  • Save joshdcomp/d65dad009d21dcee2620 to your computer and use it in GitHub Desktop.
Save joshdcomp/d65dad009d21dcee2620 to your computer and use it in GitHub Desktop.
When writing event handlers, manipulate elements relative to the element was clicked to avoid unintended concequences.
$('._ak-subscribe-close').on('click', function(){
$('._ak-email_subscribe').removeClass('_ak-email_subscribe--opened');
});
//becomes
$('._ak-subscribe-close').on('click', function(e){
var $wrapper = $(e.currentTarget).closest('._ak-email_subscribe')
$wrapper.removeClass('_ak-email_subscribe--opened');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment