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

135
Vistas
Sending id via javascript listener

For all my other options this works great (i just editing the replace part to be the correct id)..

(Note: all "'s are 'd out as in production these are dynamically created with js)

<div class=\"singlecontrol\"><span style=\"vertical-align: middle;\">Colour Picker</span><input oninput=\"updatetxtcolour(event)\" id=\"colourpicker"+textcount+"\" value=\"#dfe481\" type=\"color\" autocomplete=\"off\" ></div>
 
<script> 
function updatetxtcolour(e) {
    var ideditaded = e.target.getAttribute("id").replace("colourpicker", "");
document.getElementById("quotetext"+(ideditaded)).style.color = document.getElementById("colourpicker"+(ideditaded)).value;
}
 </script> 

But for my font picker it works like so...

<div class=\"singlecontrol\"><span style=\"vertical-align: middle;\">Font Picker</span><input id=\"font"+textcount+"\" type=\"text\" autocomplete=\"off\" ></div>
 
 
<script> 
$('#font'+(textcount))
                .fontselect()
                .on('change', function() {
                applyFont(this.value);
                });
 
        } 
 
  
    function applyFont(font) {
      console.log('You selected font: ' + font);
     
      // Replace + signs with spaces for css
      font = font.replace(/\+/g, ' ');
     
      // Split font into family and weight
      font = font.split(':');
     
      var fontFamily = font[0];
      var fontWeight = font[1] || 400;
     
      // Set selected font on paragraphs
      $('quotetext'+(textcount)).css({fontFamily:"'"+fontFamily+"'", fontWeight:fontWeight});
 
}
</script>

I'm having trouble getting the latter font picker to function in the same manner as the others, that is to pass the correct ID as these are created dynamically like so https://stackoverflow.com/a/69397361/4772471

All of my other options call a function oninput but this one uses a listener and then runs a function so i'm stumpted.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use (you must use the '#' sign):

$('#quotetext'+(textcount)).css({fontFamily:"'"+fontFamily+"'", fontWeight:fontWeight});

Instead of:

$('quotetext'+(textcount)).css({fontFamily:"'"+fontFamily+"'", fontWeight:fontWeight});

In addition, you can use template string (learn more: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals), will be much more readable:

$(`#quotetext${textcount}`)
about 4 years ago · Juan Pablo Isaza Denunciar
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