Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda