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

141
Views
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 answers
Answer question

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 Report
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!