tags:

views:

48

answers:

2

How to detect when user selects text in a textarea with JS? I used jQuery-fieldselection ,but it works only if the range.text is putted into a pre tag.It doesn't work with div.

A: 

It works and in a div ,with http://phpjs.org/functions/nl2br:480 .

lam3r4370
"JavaScript nl2br: Converts newlines to HTML line breaks"
Ondra Žižka
+3  A: 

Use the select event. It works for <textarea> and <input type="text"> elements in all mainstream browsers. Support is not universal for other elements.

document.getElementById("your_textarea").onselect = function() {
    alert("Select");
};
Tim Down