# onhighlighttext

**URL:** https://es.discourse.group/t/onhighlighttext/805
**Category:** 💡 Ideas
**Tags:** proposal
**Created:** [May 31, 2021, 11:53pm UTC](https://es.discourse.group/t/onhighlighttext/805 "2021-05-31T23:53:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![fauzan121002](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/fauzan121002/32/846_2.png) [@fauzan121002](https://es.discourse.group/u/fauzan121002)
#### Post date: [May 31, 2021, 11:53pm UTC](https://es.discourse.group/t/onhighlighttext/805/1 "2021-05-31T23:53:13Z")

</div>

I suggest to add a new event in the Javascript DOM, namely onhighlighttext.

Example :

```javascript
document.addEventListener("onhighlighttext", function(){
  alert("wow you highlighted me sir!");
});

```

Actually we can do this with getSelection by onmouseup or keyup , but it ends up with a syntax that is not neat and hard to read.

```javascript
var t = "";
function gText(e) {
    t = (document.all) ? document.selection.createRange().text : document.getSelection();
    document.getElementById('input').value = t;
}

document.onmouseup = gText;
if (!document.all) document.captureEvents(Event.MOUSEUP);

```

Besides that we can use selectionchange, but selectionchange as the latter fires so many events (up to the chars selected), you have to wait some arbitrary period to get the final selection.

I can't find any ideas and proposals about this.

---

<div class="post-metadata">

### Author: ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)
#### Post date: [June 1, 2021, 1:30am UTC](https://es.discourse.group/t/onhighlighttext/805/2 "2021-06-01T01:30:43Z")

</div>

This discourse is for the JavaScript language, which doesn’t include the DOM at all. Try [https://discourse.wicg.io](https://discourse.wicg.io)

---

<div class="post-metadata">

### Author: ![fauzan121002](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/fauzan121002/32/846_2.png) [@fauzan121002](https://es.discourse.group/u/fauzan121002)
#### Post date: [June 1, 2021, 6:44am UTC](https://es.discourse.group/t/onhighlighttext/805/3 "2021-06-01T06:44:06Z")

</div>

Thanks sir, i'll try :D
