Unable to select element in Jquery
<p>I have this code in Jquery -:</p>

<pre><code>function setCaretPos(element) {
    element.focus(); 

    if(typeof window.getSelection != "undefined" &amp;&amp; typeof document.createRange 
        != "undefined")
    {
        var range = document.createRange(); 
    referenceNode = element.getElementsByClassName("prettyTag")[0].nextSibling; 
        range.selectNode(referenceNode); range.collapse(true); 

        var sel = window.getSelection();
        sel.removeAllRanges(); sel.addRange(range);
    }
</code></pre>

<p>Function <code>setCaretPos</code> works when I do this -:<br /><br /> <code>setCaretPos(document.getElementById("editor"));</code><br /><br /> but doesn't work when I do this -:<br /> <br />
<code>var element = $("#editor"); setCaretPos(element)</code>; </p>

<p>I can only opt for the latter. How do i correct up the latter one. Thanks.. :)</p>
