Detect when user selects text in text box

How to determine when a user selects text in a text field using JS? I used jQuery-fieldselection, but it only works if range.textplaced in pre tag.It does not work with div.

+5
source share
2 answers

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

document.getElementById("your_textarea").onselect = function() {
    alert("Select");
};
+4
source

It also works in the div, http://phpjs.org/functions/nl2br:480 .

-1
source

All Articles