Using a Range object doesn't mean that it becomes selected/highlighted on
the page. It is just a way of selecting a several nodes in the document
behind the scenes (thought not exactly, it's somewhat like
document.getElementById()). As far as I know, there is no way of forcing
text on a page to be highlighted unless you give it some sort of highlighted
CSS style or style a text field to look like normal text, then call select()
on the text field.

Ted

On 9/15/07, Heath <[EMAIL PROTECTED]> wrote:
>
>
> Nothing gets selected. The correct text is logged to the console in
> FireBug. I don't think this is a jquery problem, but not sure how to
> figure this out. Thanks in advance for any help. Code below:
>
> <html>
> <head>
> <title>Testing Text Selection</title>
> <script type="text/javascript" src="http://jqueryjs.googlecode.com/
> files/jquery-1.2.js"></script>
> <script type="text/javascript">
> $(document).ready(
>         function() {
>                 $('div.pageInfo span').click(
>                         function() {
>                                 if(document.createRange) {
>                                         rangeToSelect =
> document.createRange();
>                                         rangeToSelect.selectNode(
> this.firstChild);
>                                         console.log(this.firstChild);
>                                         return false;
>                                 }
>                         }
>                 );
>         }
> );
> </script>
> </head>
>
> <body>
>         <div class="pageInfo">
>                 Some text which I don't care much about.
>                 <span>I want this text to be selected when it's clicked
> for easy
> copying.</span>
>         </div>
> </body>
> </html>
>
>


-- 
Ted

Reply via email to