# Copying a content with copy icon

**URL:** <https://meta.discourse.org/t/copying-a-content-with-copy-icon/287007>\
**Category:** Development\
**Created:** [November 29, 2023, 8:59pm UTC](https://meta.discourse.org/t/copying-a-content-with-copy-icon/287007 "2023-11-29T20:59:35Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![bekircem](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bekircem/32/44582_2.png) [@bekircem](https://meta.discourse.org/u/bekircem)\
**Post date:** [November 30, 2023, 1:30pm UTC](https://meta.discourse.org/t/copying-a-content-with-copy-icon/287007/5 "2023-11-30T13:30:17Z")

</div>

When creating a page with the Custom Wizards plugin, I want to copy the output of the variables that the plugin gives me. So we can think of it as a randomly selected area in the message content. I can assign a custom css selector to the content to be copied.

[https://github.com/keegangeorge/discourse-copy-post/blob/main/javascripts/discourse/widgets/copy-widget.js](https://github.com/keegangeorge/discourse-copy-post/blob/main/javascripts/discourse/widgets/copy-widget.js)

```plaintext
  click(attrs) {
    const copyButton = attrs.currentTarget.activeElement;
    const rawCooked = this.attrs.attrs.cooked;
    const cookedText = this.attrs.attrs.cooked.replace(/<p>(.*)<\/p>/g, "$1\n");
    let postContents = cookedText.replace(/(<([^>]+)>)/gi, "");

    if (settings.copy_raw_html) {
      postContents = rawCooked;
    }

```

const rawCooked = this.attrs.attrs.cooked;

Selector is here. I want to target the last p tag or penultimate p tag in the cooked div instead of the whole cooked. I want to target them separately if possible and place the copy icons right next to the paragraphs.

---

_[View the full topic](https://meta.discourse.org/t/copying-a-content-with-copy-icon/287007)._
