zjrJS.Doc.dE() - Stable Test Suite for zjrJS

This information lives on a webpage hosted at the following web address: 'https://www.omegajunior.net/code/zjrjs/stable.php'.

How to use zjrJS.Doc.dE() ("delete event")

Used zjrJS Version:

Stable Minified version 20141202t2322 of zjrJS.


 

Declaration
zjrJS.Doc.dE(HtmlElement Target, String eventName, function)


Goal
A cross-browser method to delete / remove event listeners from elements. dE() ensures to remove any doubles. It negates the difference between standards compliant and stubborn browsers, with a fallback for older browsers that lack a standardized DOM.

Typical usage
After getting a handle on an element, specify to which events it should stop reacting to what functions. Can be used multiple times, if necessary, to allow for halting several actions on the same or different events on the same element.

Member Type
Function.

Value Type
Object (the Target HtmlElement).

Parameters
HtmlElement Target: the element (either generated (Doc.cE() or document.createElement()) or retrieved (Doc.eid() or document.getElementByID() etc.)) which should be freed from the event listener.
String eventName: any valid lowercase event name, like "load", "click", "mouseover", and "focus". Notice that event names reflect their HTML counterparts, omitting the "on" prefix. For instance, if in HTML you'd specify an onFocus handler, the event name is "focus".
function: preferably a reference to a function specified elsewhere. Note that a function reference is its name, as one would call the function, but without parentheses () and without arguments.

Dependencies
None.

Example with declared function
<script type="text/javascript" src="zjrJS.version.js" id="zjrJS"></script>
<script type="text/javascript" defer="defer">/* <![CDATA[ */
//define a function
function sayHello(){

alert("Hello, world!");

//now we are done: remove the listener
var D=zjrJS.Doc;
var T=D.eid("button_1");
if(T){
D.dE(T, "click", sayHello);
//tell the visitor clicking serves no further purpose
D.aC(D.cT(" no more"), T);
}

//clean up memory
D=T=null;
}

var D=zjrJS.Doc;
//create a button
var T=D.cE("button");
T.id="button_1";
//add text to the button, then add the button to the page
D.aC(D.aC(D.cT("Click me"), T));

//add a click event listener to the button, supplying a reference to a previously declared function
D.aE(T, "click", sayHello);

//clean up memory
D=T=null;
/* ]]> */</script>

Download:

Download zjrJS’ latest stable build (20141202t2322) minified (7.1KB).

Download zjrJS’ latest stable build (20141202t2322) (11.9KB).

Clicky Analytics