Skip to content
This repository has been archived by the owner on Aug 19, 2021. It is now read-only.

Command: Simple DOM Grabber

bard edited this page Sep 13, 2010 · 3 revisions

Usage


    repl> var res = repl.grab();
    repl> /* click an element in the browser... */
    repl> alert(res.event.target);

Code


function grab() {
    var document = this._workContext.document;
    if(!document)
        throw new Error('No document around.');
    var result = {};
    var grabber = function(event) {
        result.event = event;
        event.stopPropagation();
        document.removeEventListener('click', grabber, true);
    };
    document.addEventListener('click', grabber, true);
    return result;
}