Skip to content
jQuert getPath - Find a (possible) jQuery selector of an HTML element.
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
TestAndBench Test suite updated (using QUnit) Sep 10, 2010
.gitmodules Update Dec 20, 2014

jQuery getPath libscore

In some specific situations you may want to identify an HTML element in an unique way - with a jQuery Selector or XPath - in order to select it in another browser - different DOM - (for example: visitor mouse & keyboard real-time monitoring).


    //Get the element's jQuery selector
    //It'll return something like this: #example-5>h4:eq(0)
    var sel = $.getPath(; //is the same as $(;

    //Send to the server what element was clicked
    //(and maybe replicate this event on the administrator screen)

    return false;

$.getPath(el); may return jQueryPath_document or jQueryPath_window. They just are equivalents for window.document and window object because jQuery doesn't have any selector for them.


var $el, path = $.getPath(window);

if(path === 'jQueryPath_document')
    $el = $(document);
else if(path === 'jQueryPath_window')
    $el = $(window);
    $el = $(path);

//So here, $el == window


Donate Bitcoins

Something went wrong with that request. Please try again.