Skip to content

Instantly share code, notes, and snippets.

@zashishz
Created February 18, 2017 10:52
Show Gist options
  • Save zashishz/c46a5222fb644b15ad7240b0d2fe9db1 to your computer and use it in GitHub Desktop.
Save zashishz/c46a5222fb644b15ad7240b0d2fe9db1 to your computer and use it in GitHub Desktop.
Event Names
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
HANDLING EVENTS
Method 1.
-------------
<button onclick="alert('Hello, World');">Some JS</button>
Method 2.
-------------
element.event = function(){
//...Event Handler Code
//...
};
Example: window.onload, fieldName.onblur, myElement.onclick ..etc.
Method 3.
-------------
myElement.addEventListener('click', myFunction, false);
Example:
div.addEventListener('onclick', function(event){
});
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<<ONLOAD EVENT>>
window.onload(function(){
//add any call you need to be executed once page loads.
});
<<TIMER EVENT>>
--------------------------------------
1. Timeout to trigger few seconds later
==> setTimeout(fnName, 1000);
2. setInterval to trigger every few seconds
==> var intervalName = setInterval(fnName, 1000);
3. clearInterval to clear any setIntervals
==> clearInterval(intervalName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment