get index value of dynamically generated child divs on mouse down and up
<p>i am working on a page which generate the dynamic DOM structure and the divs in that DOM contains the text. I want to create a jQuery or JavaScript function so that when user selects some text from page then the index of div containing the text should be stored in variables on mouse down and mouse up events. I have created the following fiddle, its the prototype of what i want but i want to be my function more generic i.e. in any pageContainer when user selects the text it should give me inital div index and final div index. One more thing that in DOM structure only div with id viewer is not dynamic anything else is dynamic</p>

<p>Here is fiddle <a href="http://jsfiddle.net/hiteshtr/pPJj3/" rel="nofollow">link</a></p>

<p>and my page's DOM structure :</p>

<pre><code>&lt;div id="viewer"&gt;
    &lt;div id="pageContainer1" &gt;
        &lt;canvas id="page1" &gt;&lt;/canvas&gt;
        &lt;div class="textLayer"&gt;
            &lt;div&gt;......some text here....&lt;/div&gt;
            &lt;div&gt;......some text here....&lt;/div&gt;
            &lt;div&gt;......some text here....&lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div id="pageContainer2" &gt;
        &lt;canvas id="page2" &gt;&lt;/canvas&gt;
        &lt;div class="textLayer"&gt;
            &lt;div&gt;......some text here....&lt;/div&gt;
            &lt;div&gt;......some text here....&lt;/div&gt;
            &lt;div&gt;......some text here....&lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;

    &lt;div id="pageContainer3" &gt;
        &lt;canvas id="page3" &gt;&lt;/canvas&gt;
        &lt;div class="textLayer"&gt;
            &lt;div&gt;......some text here....&lt;/div&gt;
            &lt;div&gt;......some text here....&lt;/div&gt;
            &lt;div&gt;......some text here....&lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>
