I was wondering if there was any way to use Javascript (or any language) to select text located in a div for the user, and I dont mean "highlight", as in, change the background color, I mean to select the text for use in copying and pasting.

...I havnt come across any solution but if there is one I would love to hear it.

Recommended Answers

All 2 Replies

You mean a user highlights a portion of text and you use JS to copy the text portion? IE, FF, and Chrome read value of range selection differently. If I remember correctly, IE uses document.selection, FF uses window.getSelection(), and Chrome uses window.getSelection() but with value of setBaseAndExtent. Search for those keywords on the Internet for more info.

No, I mean a function that SELECTS the text FOR the user. User clicks on button or link, and text from a certain div gets highlight for them. I know it can be done with text areas and such in forms, but what about text in regular divs?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.