# How to get click text and info from added textpopup?

**URL:** <https://pdfjs.community/t/how-to-get-click-text-and-info-from-added-textpopup/2984>\
**Category:** Technical Support\
**Tags:** pdfjs-express\
**Created:** [December 5, 2023, 7:26am UTC](https://pdfjs.community/t/how-to-get-click-text-and-info-from-added-textpopup/2984 "2023-12-05T07:26:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mary.j.balagtas](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mary.j.balagtas](https://pdfjs.community/u/mary.j.balagtas)\
**Post date:** [December 5, 2023, 7:26am UTC](https://pdfjs.community/t/how-to-get-click-text-and-info-from-added-textpopup/2984/1 "2023-12-05T07:26:58Z")

</div>

Good day,

I tried to add a textpopup and I would like to get the selected text and info once click the Add Tag button, just like the other textPopup button it triggers the event annotationSelected.

instance.UI.textPopup.add({  
type: ‘actionButton’,  
label: ‘AddTag’,  
onClick: () =\> console.log(‘clicked’),  
},

Thanks.

---

<div class="post-metadata">

**Author:** ![darian.chen](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@darian.chen](https://pdfjs.community/u/darian.chen)\
**Post date:** [December 6, 2023, 3:56pm UTC](https://pdfjs.community/t/how-to-get-click-text-and-info-from-added-textpopup/2984/2 "2023-12-06T15:56:17Z")

</div>

Hello Mary,

You can use the getSelectedText API under documentViewer to do this.

[https://pdfjs.express/api/Core.DocumentViewer.html#getSelectedText\_\_anchor](https://pdfjs.express/api/Core.DocumentViewer.html#getSelectedText__anchor)

```javascript
instance.UI.textPopup.add({
        type: 'actionButton',
        label: 'AddTag',
        onClick: () => {
          const selectedText = instance.Core.documentViewer.getSelectedText();
          console.log(selectedText);
        }
});

```

Best Regards,  
Darian

---

<div class="post-metadata">

**Author:** ![mary.j.balagtas](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mary.j.balagtas](https://pdfjs.community/u/mary.j.balagtas)\
**Post date:** [December 7, 2023, 4:27am UTC](https://pdfjs.community/t/how-to-get-click-text-and-info-from-added-textpopup/2984/3 "2023-12-07T04:27:48Z")

</div>

I tried it and it works. Thank you.
