JavaScript

$e.stopEvent Function

Syntax

$e.stopEvent(event as object)

Arguments

eventobject

The DOM event object.

Description

Stops an event from bubbling up the hierarchy of elements.

Discussion

The $e.stopEvent() function allows you to stop an event from bubbling up through the hierarchy of elements on a page. You pass in the event object variable that was passed into the function that is handling the event.

Example

/*This adds an event handler for the 'onkeyup' event to both the document body, and an input called 'input1'.
If the user types a key in the input, the keypressInput()  function will handle the event, and then the keypressBody() function
will ALSO handle the event (because the event 'bubbles' up through the hierarchy of element on the page. */

$e.add(document.body,'keyup',keypressBody);
$e.add('input1','keyup',keypressInput);

/*Now, assume that when the user types a key into the input, you want the keypressInput() function to be called, but NOT the keypressBody()  function.
To do this, you must stop the 'onkeyup' event from 'bubbling up'.

This is done by calling the $e.stopEvent() function inside the keypressInput() function. For example:
*/      
function keypressInput(evnt) {
    $e.stopEvent(evnt);
    //Actual code you want to handle the keypress goes here.
    //Note: the 'evnt' variable is always passed into a function that was bound using the $e.add() function.
    //The 'evnt' variable contains information about the event that happened, such as mouse position, or key pressed.
 }