Ryura wrote:
> 
> The glue code is converting your jQuery object.
> 
> var text = $('div.selectable')[0].getSelection();
> alert(text);
> 
> [0] takes the first element you selected and "removes" the jQuery
> methods, "replacing" them with the usual DOM methods.
> I don't know how supported .getSelection() is so this code may not
> work. But you can do something similar like
> 
> var text = $('div.selectable')[0].innerHTML;
> 
> Now if you wanted to do this for all div.selectable, you could do:
> 
> $('div.selectable').each(function() {
> var text = this.getSelection(); //or innerHTML or so on
> alert(text);
> })
> 

Hi, thanks for that. I understand slightly better how things work. Sorry
about posting newbie questions, but I'm one of these 'bottom-up' guys who
needs to see how things work under the hood before being able to focus on
the docs. So this kind of explanation really, really helps me in my learning
quest. (Answering to MorningZ too here, who I also thank for his links. :-))

As you feared, getSelection() will not work (document.getSelection() works,
but replacing the 'document' by the jQuery object is a no-go.

Using

$('div.selectable').each(function() {
        var text = this.innerHTML;
        alert(text);
})

sort of works, but it loses the 'selection' aspect (my script tries to
return only what was selected with the mouse) and returns each
div.selectable on the page, selected or not.

Is there a way to emulate getSelection() in jQuery? (I guess the answer is
yes.)

Thanks for the kick start,
Stéphane
-- 
View this message in context: 
http://www.nabble.com/First-steps-in-jQuery%3A-trying-to-figure-the-syntax-to-mix-standard-Javascript-with-jQuery-tp20790038s27240p20791607.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to