I have a <textarea>
HTML element. My goal is when mouse is over a word in the textarea I need to get the word and do something with it. How can it be implemented? What event should I use?
Asked
Active
Viewed 1,909 times
4

Brian Tompsett - 汤莱恩
- 5,753
- 72
- 57
- 129

IvanG
- 41
- 2
-
you need to get like **tooltip** on mouse over – htoniv May 19 '15 at 21:28
-
Just and idea. I would use ContentEditable div. Parse it's value by spaces, wrap the words into spans and put it back. And then bind hover event for that spans. http://stackoverflow.com/questions/25943803/how-to-place-span-tags-around-each-word-in-div-with-contenteditable-set – dfgd May 19 '15 at 21:29
-
possible duplicate of [What is the difference between the mouseover and mouseenter events?](http://stackoverflow.com/questions/1104344/what-is-the-difference-between-the-mouseover-and-mouseenter-events) – Cristik May 20 '15 at 05:04
1 Answers
4
As per my knowledge, you can't do that.
Only way you can do this, wrap each with element like <span>
and add on mouse hover event to all <span>
element.
<div class="spanhover"><span>Wrap</span><span>all</span><span>elements</span></div>
<script>
$(document).ready(function () {
$('.spanhover span').bind('mouseenter', function () {
alert($(this).html() + " is your word");
});
});
</script>

Maddy
- 907
- 3
- 10
- 25
-
2I thought about this. But I need something where I can edit text. I can make the div to be editable (contenteditable). But how to support text-to-span converting when the text is changed? It seems like there is too many edge cases – IvanG May 20 '15 at 12:08