/ Published in: JavaScript
                    
                                        
Link body class names to trigger javascript. It requires jQuery.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
$(function(){
//jquery references the body for grabbing class info and for general awesomness
var body = $('body');
jQuery.fx.interval = 5;
//apply all methods as root level functions
var root = this;
//counter
var i;
// the goods are in here.
var pageScripts = {
//init is called automatically
//use to set up global stuff
init:function(){
}
};
//determine if any of the pageScripts match the class of the body and call it/them
//keep track of how many properties have been executed
var numRan = 0;
//split up the classes used in the body
//array of classes used in the body's class attribute
var bodyClasses = body.attr("class").split(" ");
//call init
pageScripts.init();
//loop through and execute all
for(i in bodyClasses){
if(pageScripts[ i ]){
numRan++;
pageScripts[ i ].apply(root, []);
}
}
log(numRan + " methods have been executed");
});
URL: http://www.digitalsurgeons.com
Comments
 Subscribe to comments
                    Subscribe to comments
                
                