0

I want to run some code while user selecting a text. The 'while' is very important. onselect event is fired only after the text has been selected, so it doesn't help much.

Basically I have a situation that a very big message is being shown and it hides part of a paragraph. So I want to hide the message automatically if the user starts to select something in the paragraph.

Alvarez
  • 1,303
  • 1
  • 10
  • 28
  • 1
    Hope this thread will help you: http://stackoverflow.com/questions/3545018/selected-text-event-trigger-in-javascript – osmancode Oct 18 '14 at 12:27

1 Answers1

2

Try using flags (from this question):

var isMouseDown = false;
document.getElementById("para").onmousedown = function () {
    isMouseDown = true;
};
document.getElementById("para").onmouseup = function () {
    isMouseDown = false;
    this.style.background = "white";
};
document.getElementById("para").onmousemove = function () {
    if (isMouseDown) { /* do drag things */
        this.style.background = "red";
    }
};

Demonstration. (Try selecting the text and just clicking it).

Community
  • 1
  • 1
Mohammad Areeb Siddiqui
  • 9,795
  • 14
  • 71
  • 113