View Single Post
  #3 (permalink)  
Old 11-21-2006, 07:40 AM
Jonas Raoni
Guest
 
Posts: n/a
Default Re: Select text within a div tag by clicking on content of div tagor a button?

David Golightly escreveu:
> visu wrote:
>> Wondering if anyone can tell me if it's possible to have Javascript
>> select the contents of a div tag with a unique id by clicking
>> somewhere in the contents of that div tag?


It's not very reliable what I've wrote, but take a look:

function select(o){
if(window.getSelection && document.createRange){
var s = window.getSelection(), r = document.createRange();
r.selectNode(o), s.removeAllRanges(), s.addRange(r);
}
else if(o.createTextRange)
o.createTextRange().select();
}

select(document.body);

> Alternativley, you might want to just give users a textarea they can
> dump text into.


As a user I preffer to choose what I'll copy and paste, but if the job
is a kind of routine, then I think you should copy the html/text of the
element instead of selecting it visually.


--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Reply With Quote