I am trying to create a script that detects when a person is done highlighting text. To do so, I've got an onclick event in the div containing the p with the text in it. If you click anywhere in the yellow space, the alert box should come up on the click event. If you highlight a portion of the text (but not all the way to the end of the text!) the event will fire.
The bug occurs when you highlight up to and including the last word "text". The event will not fire.
I can duplicate this in Chrome and Safari but it seems to work OK in Firefox. Haven't tested IE.
<html>
<head>
<style>
div{background-color:#FFFF00}
</style>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
function mouseClicked()
{
alert("mouseClicked");
}
</script>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
</div>
<div onClick='mouseClicked()'>
<p>Try to highlight this text</p>
</div>
</body>
</html>
Any ideas? Thanks, Kshanti
Edit: Just figured out it works with onmouseup event used like this: document.onmouseup=mouseClicked;
From Javascript: How to detect if a word is highlighted
Still weird that it doesn't work with onclick though.