zjrJS.Doc.eS() - Beta Test Suite for zjrJS

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

How to use zjrJS.Doc.eS() ("event source")

Used zjrJS Version:

Stable Minified version 20141202t2322 of zjrJS.

There is no newer Beta version available.


 

Declaration
zjrJS.Doc.eS(Event evt)

Goal
A cross-browser method to get a hold of the source element (or target) of an event. It negates the difference between standards compliant and stubborn browsers.

Typical usage
When dealing with a collection of elements that all need to perform the same action on the same event, you could create specified, parametrised handlers, uniquely identifying each of the cooperating elements. Or you could specify one single handler to a parent element, and use the event's source (or target) to identify which element needs to act.

Member Type
Function.

Value Type
Object (the source HtmlElement which originated the event).

Parameters
Event evt: the global or specific event automatically created by the browser's event system.

Dependencies
None, but do take a look at zjrJS.Doc.eP().

Example
<script type="text/javascript" src="zjrJS.version.js" id="zjrJS"></script>
<script type="text/javascript">/* <![CDATA[ */
//define a function to alert the id of a clicked button
function sayHello(evt){
alert(zjrJS.Doc.eS(evt).id);
}
//tell all buttons in a container to say hello
zjrJS.Doc.aE(zjrJS.Doc.eid("myButtonList"), "click", sayHello);
/* ]]> */</script>


Notice that this way, only 1 event handler is defined and added. That could save quite a bit of memory. Since by default the events propagate upwards through the node hierarchy, clicking a button will result in clicking its container, which results in the desired action. Therefore it is wise to check whether the event source's tagName is correct or cancel the propagation by using zjrJS.Doc.eP(); in the above example, the container itself will count as an event source and will say hello too.

Download:

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

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