diff --git a/reflex/components/datadisplay/shiki_code_block.py b/reflex/components/datadisplay/shiki_code_block.py
index 71e603021..7c46d8f23 100644
--- a/reflex/components/datadisplay/shiki_code_block.py
+++ b/reflex/components/datadisplay/shiki_code_block.py
@@ -22,11 +22,10 @@ from reflex.vars.function import FunctionStringVar
from reflex.vars.sequence import StringVar, string_replace_operation
-def copy_script(id: str, code: StringVar | str) -> Any:
- """Copy script for the code block.
+def copy_script(code: StringVar | str) -> Any:
+ """Copy script for the code block and modify the child SVG element.
Args:
- id (str): The ID of the button element.
code (str): The code to be copied.
Returns:
@@ -34,33 +33,41 @@ def copy_script(id: str, code: StringVar | str) -> Any:
"""
return call_script(
f"""
-const button = document.getElementById('{id}');
-const icon = button.querySelector('svg');
-const originalPath = icon.innerHTML;
-const checkmarkPath = '';
+// Event listener for the parent click
+document.addEventListener('click', function(event) {{
+ const parent = event.target.closest('div'); // Assumes the parent is a
or any container
+ if (parent) {{
+ const svgIcon = parent.querySelector('svg'); // Always targets the