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

88
Vistas
Custom font javascscript

So I have some code to change my font, but I also want an option to input a custom font:
Javascript:

changeFont = function(){
    var select = document.getElementById('font');
    var fontValue = select.options[select.selectedIndex].value;
    console.log(value);
    if (fontValue === "custom"){
        var custom = document.getElementById("font");
        custom.style.visibility='visible'
    }
    else{
        document.documentElement.style
        .setProperty('--font', fontValue);
    }
    
    
}

Html:
 <select id="font" style="margin-left:10px; margin-right: 10px;" onchange="changeFont()">
        <option value="Fira Code">Defualt</option>
        <option value="sans-serif">Sans Serif</option>
        <option value="serif">Serif</option>
        <option value="custom">Custom</option>


        
      
    </select> 
    <h5 class="customFont">Custom Font</h5>
<input class="customFont" id="customFont">

But unfortuantley it doesnt work, is my if statment wrong or something, im kinda stuck rn. Thanks

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

0

I guess you need a select to get the pre-defined font value and an input to get the customized font value. If you want it, you can try following code:

changeFont = function() {
  var select = document.getElementById('font');
  var fontValue = select.options[select.selectedIndex].value;

  if (fontValue === "custom") {
    var custom = document.getElementById("customFont");

    custom.style.visibility = 'visible'
  } else {
    document.documentElement.style.setProperty('font-family', fontValue);
  }
}

inputFont = function() {
  var custom = document.getElementById("customFont");

  document.documentElement.style.setProperty('font-family', custom.value);
}
<div id="main">
  <select id="font" style="margin-left:10px; margin-right: 10px;" onchange="changeFont()">
    <option value="Fira Code">Defualt</option>
    <option value="sans-serif">Sans Serif</option>
    <option value="serif">Serif</option>
    <option value="custom">Custom</option>
  </select>

  <h5 class="customFont">Custom Font</h5>
  <input class="customFont" id="customFont" onchange="inputFont()">
</div>

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