Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
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 enter image description here

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!