Skip to content

Command: Simple DOM Grabber

bard edited this page · 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;
}

Something went wrong with that request. Please try again.