# IMPLEMENTED: Make the element IDs copy to clipboard on click

**URL:** <https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349>\
**Category:** Feature Requests / Improvements\
**Created:** [June 6, 2022, 8:25pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349 "2022-06-06T20:25:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![khan360](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/k/a6a055/32.png) [@khan360](https://forum.bricksbuilder.io/u/khan360)\
**Post date:** [June 6, 2022, 8:25pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/1 "2022-06-06T20:25:03Z")

</div>

At times I have to use their IDs and am left with typing them instead by seeing and the Bricks ID structure is not a convenient one to remember so why not allow copying the ID on clicking a key that is maybe next to the ‘Rename ID’ pencil icon?

I am surprised even in the rename field, the existing ID doesn’t get auto typed to edit/copy.

![Issue](https://forum.bricksbuilder.io/uploads/default/original/2X/f/f1a0154dd8588c1a5d8a2866bffc24cfa86ee5d9.jpeg)

---

<div class="post-metadata">

**Author:** ![yankiara](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/yankiara/32/2114_2.png) [@yankiara](https://forum.bricksbuilder.io/u/yankiara)\
**Post date:** [June 7, 2022, 3:33pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/2 "2022-06-07T15:33:44Z")

</div>

+1 for both class and id copy to clipboard 🙂

---

<div class="post-metadata">

**Author:** ![wolfgang](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/wolfgang/32/26083_2.png) [@wolfgang](https://forum.bricksbuilder.io/u/wolfgang)\
**Post date:** [July 1, 2022, 8:09am UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/4 "2022-07-01T08:09:50Z")

</div>

Also +1 for that.

@timmse what do you think about it, any chance that we can get a static ID text field somewhere above the word “container” or anywhere else to copy and paste the ID?

I’ve also mentioned in facebook that there is a UX problem, when giving an Element a custom ID via Advanced-\>CSS-\>ID there’s no chance that we can find out the ID of the element without removing that ID!

> **[Bricks Community | Facebook](https://www.facebook.com/groups/brickscommunity/permalink/986378435360010/)**
>
> Welcome to the official Bricks Theme Community :)
> 
> Bricks is a visual site builder for WordPress. Made for people who value performance, customizability, and design.
> 
> We launched a bit over a year...

TIA for your answer! 😉

---

<div class="post-metadata">

**Author:** ![sunny](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/sunny/32/3575_2.png) [@sunny](https://forum.bricksbuilder.io/u/sunny)\
**Post date:** [July 8, 2022, 4:54am UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/5 "2022-07-08T04:54:49Z")

</div>

Would really like to see this as well. Being able to copy a class name is pretty essential when using BEM to name your classes 🙂

---

<div class="post-metadata">

**Author:** ![beziehungsweise](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/b/e19adc/32.png) [@beziehungsweise](https://forum.bricksbuilder.io/u/beziehungsweise)\
**Post date:** [July 8, 2022, 9:21am UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/6 "2022-07-08T09:21:09Z")

</div>

Fully second this … have also been missing a copy-id function heavily!

---

<div class="post-metadata">

**Author:** ![cmstew](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/c/65b543/32.png) [@cmstew](https://forum.bricksbuilder.io/u/cmstew)\
**Post date:** [September 22, 2022, 8:41pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/7 "2022-09-22T20:41:15Z")

</div>

I would very much like to see this added. Or at least a small copy icon. I understand that clicking is already tied to opening the global class menu.

---

<div class="post-metadata">

**Author:** ![cmstew](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/c/65b543/32.png) [@cmstew](https://forum.bricksbuilder.io/u/cmstew)\
**Post date:** [October 7, 2022, 5:06am UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/8 "2022-10-07T05:06:39Z")

</div>

For those interested in a DIY method while we wait, I threw something together today. If you find any issues, let me know.

 ![Screen Shot 2022-10-06 at 11.07.05 PM](https://forum.bricksbuilder.io/uploads/default/original/2X/f/f2ea377c3afbfe7d17317bd1cecf1d2056f35af0.png)

Add this to your `functions.php` file:

```auto
add_action( 'wp_enqueue_scripts', function() {
	if ( bricks_is_builder_main() ) {
		wp_enqueue_script( 'stu-element-copy-id', get_stylesheet_directory_uri() . '/stu-element-copy-id.js');
	}
} );

```

And put this in a file called `stu-element-copy-id.js` inside your child theme:

```auto
function stuElementCopyId() {
	const copyIcon = '<svg version="1.1" viewBox="0 0 30 30" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="bricks-svg"><path d="M9.5,5h11c0.276,0 0.5,-0.224 0.5,-0.5v-1c0,-1.378 -1.122,-2.5 -2.5,-2.5h-1.774c-0.353,-0.609 -1.007,-1 -1.726,-1c-0.718,0 -1.373,0.39 -1.726,1h-1.774c-1.378,0 -2.5,1.122 -2.5,2.5v1c0,0.276 0.224,0.5 0.5,0.5Zm14.766,-2h-1.766c-0.276,0 -0.5,0.224 -0.5,0.5v1c0,0.828 -0.672,1.5 -1.5,1.5h-11c-0.826,0 -1.5,-0.672 -1.5,-1.5v-1c0,-0.276 -0.224,-0.5 -0.5,-0.5h-1.765c-0.956,0 -1.735,0.781 -1.735,1.739v23.523c0,0.957 0.779,1.738 1.735,1.738h18.529c0.957,0 1.736,-0.781 1.736,-1.739v-23.522c0,-0.958 -0.778,-1.739 -1.734,-1.739Z" fill="currentColor"></path></svg>';

	const span = document.createElement('span');
	span.setAttribute('class', 'bricks-svg-wrapper stu-copy');
	span.setAttribute('data-balloon', 'Copy (Element ID)');
	span.setAttribute('data-balloon-pos', 'top-right');
	span.innerHTML = copyIcon;

	const style = document.createElement('style');
	style.innerHTML = `
		#bricks-panel-element-classes .active-class .actions .stu-copy {
			visibility: hidden;
		}
		#bricks-panel-element-classes .active-class:hover .actions .stu-copy {
			visibility: visible;
		}
	`;
	document.head.appendChild(style);

	const targetNode = document.getElementById('bricks-panel'),
		  config = {childList: true, subtree: true},
		  callback = (mutationList, observer) => {
			  for (const mutation of mutationList) {

				      // If changing element being edited
				  if (mutation.target.id == 'bricks-panel-element' ||
					  // If going from settings panel or element picker to editing element
					  mutation.addedNodes.length !== 0 && mutation.addedNodes[0].id === 'bricks-panel-element') {

					  const activeClass = document.querySelector('#bricks-panel-element-classes .active-class'),
							placeholder = activeClass.querySelector('input').getAttribute('placeholder'),
							dataId = document.getElementById('bricks-builder-iframe').contentWindow.document.querySelector(placeholder).getAttribute('data-id'),
							actionsContainer = activeClass.querySelector('div.actions');

					  actionsContainer.prepend(span);

					  const copy = actionsContainer.querySelector('span.stu-copy');

					  copy.addEventListener('click', function(e) {
						  e.stopPropagation();

						  // Comment this line and uncomment the next line if you'd prefer getting the bricks set element id always
						  navigator.clipboard.writeText(placeholder);

						  // Uncomment this line if you want the bricks set element id
						  // navigator.clipboard.writeText(dataId);
					  });

				  }
			  }
		  };

	const observer = new MutationObserver(callback);

	observer.observe(targetNode, config);
}

document.addEventListener('DOMContentLoaded', function() {
	stuElementCopyId();
});

```

---

<div class="post-metadata">

**Author:** ![Silverlion009](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@Silverlion009](https://forum.bricksbuilder.io/u/Silverlion009)\
**Post date:** [October 7, 2022, 2:29pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/9 "2022-10-07T14:29:24Z")

</div>

Thanks, i hope it will be added built-in in bricks builder  
It is very helpful for custom css

---

<div class="post-metadata">

**Author:** ![Akun](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/akun/32/20902_2.png) [@Akun](https://forum.bricksbuilder.io/u/Akun)\
**Post date:** [November 21, 2022, 1:41am UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/10 "2022-11-21T01:41:01Z")

</div>

+1 really nice UX

please implement this soon

---

<div class="post-metadata">

**Author:** ![khan360](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/k/a6a055/32.png) [@khan360](https://forum.bricksbuilder.io/u/khan360)\
**Post date:** [November 21, 2022, 10:10am UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/11 "2022-11-21T10:10:37Z")

</div>

Beautiful snippet. Thank you.

---

<div class="post-metadata">

**Author:** ![cmstew](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/c/65b543/32.png) [@cmstew](https://forum.bricksbuilder.io/u/cmstew)\
**Post date:** [November 22, 2022, 2:03am UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/12 "2022-11-22T02:03:13Z")

</div>

Hey all,

There’s been a few bugs reported lately. Mainly it doesn’t work with custom ID’s. I can’t update my original reply because too much time has passed. I’ve included a link to a GitHub project that has a fix. I’ll include future fixes there as well:

> **[GitHub - cmstew/stu-bricks-copy-id](https://github.com/cmstew/stu-bricks-copy-id/)**
>
> Contribute to cmstew/stu-bricks-copy-id development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![khan360](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/k/a6a055/32.png) [@khan360](https://forum.bricksbuilder.io/u/khan360)\
**Post date:** [November 22, 2022, 7:10pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/13 "2022-11-22T19:10:45Z")

</div>

Much thanks, mate 🙂

---

<div class="post-metadata">

**Author:** ![portseif](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/portseif/32/1608_2.png) [@portseif](https://forum.bricksbuilder.io/u/portseif)\
**Post date:** [March 8, 2023, 6:16pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/14 "2023-03-08T18:16:59Z")

</div>

@cmstew Thank you for you contribution. Much appreciated \<3!

Here’s an updated version that handles active class as well:

> **[GitHub - portseif/stu-bricks-copy-element: Bricks Builder copy element ID and...](https://github.com/portseif/stu-bricks-copy-element)**
>
> Bricks Builder copy element ID and active class. Contribute to portseif/stu-bricks-copy-element development by creating an account on GitHub.

And if you use a snippet plugin like Code Snippets, WPCodebox, etc. just plug this in a snippet:

**Updated 3/24/23**

```auto
<?php

add_action( 'wp_enqueue_scripts', function() {
	if ( bricks_is_builder_main() ) { ?>
        <script>
            document.addEventListener('DOMContentLoaded', () => {
                stuElementCopyElement();
            });

            function stuElementCopyElement() {
                const copyIdIcon = '<svg width="12" height="13" viewBox="0 0 12 13" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M4 1.549a.5.5 0 0 1 .5.5v2h3v-2a.5.5 0 0 1 1 0v2H10a.5.5 0 0 1 0 1H8.5v3H10a.5.5 0 0 1 0 1H8.5v2a.5.5 0 1 1-1 0v-2h-3v2a.5.5 0 1 1-1 0v-2H2a.5.5 0 0 1 0-1h1.5v-3H2a.5.5 0 0 1 0-1h1.5v-2a.5.5 0 0 1 .5-.5Zm3.5 6.5v-3h-3v3h3Z" fill="currentColor"/></svg>';
                const copyClassIcon = '<svg width="12" height="13" viewBox="0 0 12 13" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M8.146 3.695a.5.5 0 0 1 .708 0l2.5 2.5a.5.5 0 0 1 0 .707l-2.5 2.5a.5.5 0 1 1-.708-.707l2.147-2.146-2.147-2.147a.5.5 0 0 1 0-.707Zm-4.292 0a.5.5 0 0 1 0 .707L1.707 6.55l2.147 2.146a.5.5 0 1 1-.708.707l-2.5-2.5a.5.5 0 0 1 0-.707l2.5-2.5a.5.5 0 0 1 .708 0ZM7.108 1.56a.5.5 0 0 1 .38.597l-2 9a.5.5 0 0 1-.976-.217l2-9a.5.5 0 0 1 .596-.38Z" fill="currentColor"/></svg>';

                // Destructuring for efficient future use
                const { querySelector } = document;
                const { contentWindow } = document.getElementById('bricks-builder-iframe');

                // Create copy id icon
                const spanId = document.createElement('span');
                spanId.setAttribute('class', 'bricks-svg-wrapper stu-copy-id');
                spanId.setAttribute('data-balloon', 'Copy (Element ID)');
                spanId.setAttribute('data-balloon-pos', 'top-right');
                spanId.innerHTML = copyIdIcon;

                // Create copy class icon
                const spanClass = document.createElement('span');
                spanClass.setAttribute('class', 'bricks-svg-wrapper stu-copy-class');
                spanClass.setAttribute('data-balloon', 'Copy (Element Class)');
                spanClass.setAttribute('data-balloon-pos', 'top-right');
                spanClass.innerHTML = copyClassIcon;
                
                // Create style tag and append to head
                document.head.appendChild(document.createElement('style')).innerHTML = `
                    #bricks-panel-element-classes .active-class .actions :is(.stu-copy-id, .stu-copy-class) {
                            visibility: hidden;
                    }
                    #bricks-panel-element-classes .active-class:hover .actions :is(.stu-copy-id, .stu-copy-class) {
                            visibility: visible;
                    }
                `;

                // MutationObserver declarations
                const targetNode = document.querySelector('#bricks-panel');
                const config = { childList: true, subtree: true };

                // Callback function to detect DOM changes within #bricks-panel
                const callback = (mutationList, observer) => {
                    for (const mutation of mutationList) {
                        if (mutation.target.id === 'bricks-panel-element' || (mutation.addedNodes.length > 0 && mutation.addedNodes[0].id === 'bricks-panel-element')) {
                            const activeClass = document.querySelector('#bricks-panel-element-classes .active-class');
                            const placeholder = activeClass.querySelector('input').getAttribute('placeholder');
                            const bricksCanvas = contentWindow.document;
                            const dataId = bricksCanvas.querySelector(placeholder) ? bricksCanvas.querySelector(placeholder).getAttribute('data-id') : null;
                            const actionsContainer = activeClass.querySelector('div.actions');
                            const elementClass = document.querySelector('#bricks-panel-element-classes .element-classes .element-class.active > .name')?.innerText ?? null;
                            
                            if (elementClass) {
                                actionsContainer.prepend(spanId, spanClass);

                                const copyClass = actionsContainer.querySelector('span.stu-copy-class');
                                copyClass.addEventListener('click', (e) => {
                                    e.stopPropagation();
                                    navigator.clipboard.writeText(elementClass);
                                });
                            } else {
                                actionsContainer.prepend(spanId);

                                const copyId = actionsContainer.querySelector('span.stu-copy-id');
                                copyId.addEventListener('click', (e) => {
                                    e.stopPropagation();
                                    navigator.clipboard.writeText(placeholder);
                                });
                            }
                        }
                    }
                };
                
                // Create the MutationObserver object and monitor changes within #bricks-panel
                const observer = new MutationObserver(callback);
                observer.observe(targetNode, config);
            }
        </script>
    <?php }
} );

```

---

<div class="post-metadata">

**Author:** ![cmstew](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/c/65b543/32.png) [@cmstew](https://forum.bricksbuilder.io/u/cmstew)\
**Post date:** [March 8, 2023, 9:30pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/15 "2023-03-08T21:30:55Z")

</div>

Hey Chris,

You’re very welcome. Thanks for the contribution. I’ll take a closer look this evening. 🙂

---

<div class="post-metadata">

**Author:** ![mackarias](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/mackarias/32/23119_2.png) [@mackarias](https://forum.bricksbuilder.io/u/mackarias)\
**Post date:** [March 24, 2023, 12:22pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/16 "2023-03-24T12:22:57Z")

</div>

+1 for this feature, thanks for the custom code snippets team 🙂

---

<div class="post-metadata">

**Author:** ![mackarias](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/mackarias/32/23119_2.png) [@mackarias](https://forum.bricksbuilder.io/u/mackarias)\
**Post date:** [March 24, 2023, 12:31pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/17 "2023-03-24T12:31:42Z")

</div>

This isn’t working for me. I tried the latest code on your git page.

First element that I copy the ID for works fine but if I try to copy a second elements ID I still have the first element ID on my clipboard.

---

<div class="post-metadata">

**Author:** ![jornes](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/jornes/32/31340_2.png) [@jornes](https://forum.bricksbuilder.io/u/jornes)\
**Post date:** [March 24, 2023, 2:28pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/18 "2023-03-24T14:28:15Z")

</div>

+1 for this addition. By copying the IDs/Classes this way we don’t need to manually type it(wrongly typed sometimes).

---

<div class="post-metadata">

**Author:** ![thomas](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/thomas/32/3_2.png) [@thomas](https://forum.bricksbuilder.io/u/thomas)\
**Post date:** [March 24, 2023, 3:41pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/19 "2023-03-24T15:41:03Z")

</div>

Great idea 👌

We could provide something like this:

![bricks-copy-element-id-to-clipboard](https://forum.bricksbuilder.io/uploads/default/original/2X/b/bc0836ade6713a72f081e8c804946e684801f3b0.png)

So after clicking the new “copy” icon (not yet in Bricks) the value in the clipboard is `#brxe-yfiosu`.  
Or better just `brxe-yfiosu` (without the leading `#`)?

Agreed on populating the existing element ID after you click “rename” like this:

![bricks-rename-element-id-populate](https://forum.bricksbuilder.io/uploads/default/original/2X/a/a87855f236eab54288c8ad123d0284be897e692c.png)

---

<div class="post-metadata">

**Author:** ![HeroRox](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/h/8baadc/32.png) [@HeroRox](https://forum.bricksbuilder.io/u/HeroRox)\
**Post date:** [March 24, 2023, 4:02pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/20 "2023-03-24T16:02:12Z")

</div>

With # is okay - most of the time anyway I think. Maybe even less support requests why # was not copied with it. 🥳

---

<div class="post-metadata">

**Author:** ![jornes](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/jornes/32/31340_2.png) [@jornes](https://forum.bricksbuilder.io/u/jornes)\
**Post date:** [March 24, 2023, 4:15pm UTC](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349/21 "2023-03-24T16:15:11Z")

</div>

It’s okay with `#`. Thomas.

[Next page](https://forum.bricksbuilder.io/t/implemented-make-the-element-ids-copy-to-clipboard-on-click/3349.md?page=2)
