Hello I have this code below
<h3 class="project discord" data-title="test1234"><i class='bx bx-fw bx-tada-hover bxl-discord-alt'></i>Discord</h3>
And I would like when the data-title appears it would be possible to copy the text of the data-title.
Hello I have this code below
<h3 class="project discord" data-title="test1234"><i class='bx bx-fw bx-tada-hover bxl-discord-alt'></i>Discord</h3>
And I would like when the data-title appears it would be possible to copy the text of the data-title.
To copy text from a data-title attribute, you can use the getAttribute method in JavaScript to retrieve the text from the attribute and then use the execCommand method with the 'copy' argument to copy it to the clipboard. Here is an example:
// Get the element with the data-title attribute
var element = document.querySelector('[data-title]');
// Get the text from the data-title attribute
var text = element.getAttribute('data-title');
// Copy the text to the clipboard
document.execCommand('copy', false, text);
Keep in mind that this only works if the user has interacted with the page in some way, such as clicking on an element, in order to trigger the JavaScript code. Additionally, some browsers may require the user to grant permission for the clipboard access.