Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda