Hello,

I have an HTML page where when user clicks on a paragraph I want to
find out its path. I have written a jquery script for it:

jQuery.fn.extend({
    getPath: function( path ) {
        // The first time this function is called, path won't be
defined.
        if ( typeof path == 'undefined' ) path = '';
        if ( this.is('html') )
            return '/html' + path;
        // Add the element name.
        var cur = this.get(0).nodeName.toLowerCase();
        var index = this.prevAll().length;
        // Recurse up the DOM.
        return this.parent().getPath( '/' + cur + '[' + index + ']' +
path );
    }
});

On an html page like this
<body>
        <h1> Testing </h1>
        <ul>
            <li>
            <p> Except when the winds rise to a high speed, we seem to
live in a very tranquil world.</p>
            <p> In addition to this the earth revolves round the sun
at a speed of more than a thousand miles a minute.</p>
            </li>
            <li>
            <p> Circling round the earth, in the same way as the earth
circles round the sun, is our moon. </p>
            </li>
        </ul>
</body>

Clicking on the second paragraph "Except when the winds..." generates /
html/body[1]/ul[1]/li[0]/p[1]. I am not getting why body and ul have
index 1. Please help. Sorry for the long mail.

Reply via email to