'How to copy multiple div content which is next to the plus sign in Javascript or PHP
I need to implement something like Google Keywords Theme that click the plus sign to store the value of the div in an array. The problem it just copies the first printed value only.
This's the php code
echo "<div id=\"copying_keywords\" class=\" shadow-lg bg-body rounded border border-3 border-dark rounded-pill overlay view zoom hover-zoom\" style=\"opacity:0.7; display:inline-block; padding:5px; margin:1px; color:black; background: #3f729b; border: 1px solid #847577; border-radius:50px;\"> ". $Youtube_tags_arr[$j + $i] . "
<button id=\"keywords\" onclick=\"func_keywords()\" type=\"button\" class=\"btn btn-default btn-sm\"> <span class=\"\"></span> <i class=\"fa-solid fa-plus\"></i> </button> </div>";
This is the Javascript Code 6
<script type="text/javascript">
function func_keywords(){
alert('helllo there');
if (window.getSelection) {
if (window.getSelection().empty) { // Chrome
window.getSelection().empty();
} else if (window.getSelection().removeAllRanges) { // Firefox
window.getSelection().removeAllRanges();
}
} else if (document.selection) { // IE?
document.selection.empty();
}
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById("copying_keywords"));
range.select().createTextRange();
document.execCommand("copy");
alert(range);
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById("copying_keywords"));
window.getSelection().addRange(range);
document.execCommand("keywords");
alert(range);
}
}
</script>
This's how it works whatever the plus sign I press it copies only the first value

Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
