Skip to content

Instantly share code, notes, and snippets.

@hayatbiralem
Created April 16, 2014 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayatbiralem/10871363 to your computer and use it in GitHub Desktop.
Save hayatbiralem/10871363 to your computer and use it in GitHub Desktop.
Add/Remove class on event helpers
// add/remove class on event helpers
Helper.addClassOnEvent = function(el, ev, cl){
var $el = $(el);
if(!$el.length || !cl || typeof ev !== "string" || typeof cl !== "string") {
return false;
}
$el.each(function(){
// if(!Modernizr.hasEvent(ev, this)){
// return true;
// }
var $trigger = $(this)
, onEv = {}
;
onEv[ev] = function(){
$trigger.addClass(cl);
};
$(this).on(onEv);
});
};
Helper.removeClassOnEvent = function(el, ev, cl){
var $el = $(el);
if(!$el.length || !cl || typeof ev !== "string" || typeof cl !== "string") {
return false;
}
$el.each(function(){
// if(!Modernizr.hasEvent(ev, this)){
// return true;
// }
var $trigger = $(this)
, onEv = {}
;
onEv[ev] = function(){
$trigger.removeClass(cl);
};
$(this).on(onEv);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment