Yeah I realized I wasn't adding the range to the selection object.
This is what I finally came up with:

                $('div.pageInfo span').click(
                        function() {
                                // firefox
                                if(document.createRange) {
                                        rangeToSelect = document.createRange();
                                        
rangeToSelect.selectNode(this.firstChild);
                                        curSelect = window.getSelection();
                                        curSelect.addRange(rangeToSelect);
                                        //console.log(this.firstChild);
                                        return false;
                                }
                                // ie
                                if(document.body && 
document.body.createTextRange) {
                                        range = document.body.createTextRange();
                                        range.moveToElementText(this);
                                        range.select();
                                        return false;
                                }
                        }
                );

On Sep 16, 12:22 am, "Theodore Ni" <[EMAIL PROTECTED]> wrote:
> 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