![]()
Snippets of A |
|
|
What are snippets? |
|
on or not.
function addevent(element, event, func){ if(typeof func=="string"){func=window[func];}; if(typeof element=="string"){element=document.getElementById(element);}; if(!element || typeof event!="string" || typeof func!="function"){return false;}; event=event.toLowerCase(); if(typeof element['addEventListener']!="undefined"){ if(event.indexOf('on')>-1){event=event.replace(/^on/, '');}; element.addEventListener(event, func, false); return true; } else if(typeof element['attachEvent']!="undefined"){ if(event.indexOf('on')!=0){event='on'+event;}; element.attachEvent(event, func); return true; } else{ if(event.indexOf('on')!=0){event='on'+event;}; element[event]=func; }; return false; /*keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
getElementById) or a string: in the latter case it is presumed it represents a valid id assigned to a layer.
"onclick" or "click" would work).
false in case of wrong inputs or failure, or boolean true.
addEventListener or the attachEvent javascript built in methods are detected as available, the function to be assigned is assigned without using them: in this case this implies that, if any other event handler for that event had already been previously assigned to that element, it will be overwritten by the new assigned one.
addEventListener or attachEvent are available, each subsequent assignment will assign the task again to the element.
on or not, and pass arguments to the attached functions.
function addevent2(element, event, func, argumentsArray){/*presumes func uses javascript closures*/ if(typeof func=="string"){func=window[func];}; if(typeof element=="string"){element=document.getElementById(element);}; if(!element || typeof event!="string" || typeof func!="function"){return false;}; event=event.toLowerCase(); if(typeof element['addEventListener']!="undefined"){ if(event.indexOf('on')>-1){event=event.replace(/^on/, '');}; element.addEventListener(event, func(argumentsArray), false); return true; } else if(typeof element['attachEvent']!="undefined"){ if(event.indexOf('on')!=0){event='on'+event;}; element.attachEvent(event, func(argumentsArray)); return true; } else{ if(event.indexOf('on')!=0){event='on'+event;}; element[event]=func(argumentsArray); }; return false; /*keep this comment to reuse freely: http://www.fullposter.com/?1 */}Remove colors
function foofunc1(myargs){ return function(/*NO args here*/){ /*your code goes HERE; the argument named myargs is available in here too and can be called from within this area.*/ } }Remove colors
<div id="foofoo" style="border:#000000 1px solid;">Hallo World</div> <script> function foofunc1(myargs){ return function(/*NO args here*/){ var element=document.getElementById(myargs[0]); var aValue=myargs[1]; element.style.cssText=element.style.cssText+';'+aValue; } } addevent2('foofoo', 'click', foofunc1, ['foofoo', 'border-color:#ff0000;']) </script> Click on Hallo world above now. Its border will become red.Remove colors