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

288
Vistas
Why is the fontFamily of this ejs variable undefined?

I have a website where users can submit text in whichever kind of font they'd like, and when their text is loaded on an ejs file, it displays the text in their chosen font. Here is the means of selecting the font:

<label for="fonts">Choose a font:</label>
<select name="fontType" id="fonts">
  <option value="Verdana">Verdana</option>
  <option value="Times New Roman">Times New Roman</option>
  <option value="Georgia">Georgia</option>
</select>
<br><br>

In which, the text submitted and font chosen are both saved as String values into a MongoDB cluster.

On the ejs file, the text the user submitted is saved in variable t, and font in variable font:

<% let t = numbers.usertext%> <% let font = numbers.fontType%>

In which "numbers" is the object put forth by the index.js file in the form:

res.render("template.ejs", { numbers: numbers});

Then, later within a <script> tag, I define some JS varaibles:

let t = "<%= t %>";  let font = "<%= font %>;"

I thought all that would need to be done is something like this:

t.style.fontFamily = font;

However, I receive an error that "Cannot set properties of undefined (setting 'fontFamily')" and I do not know why this is. I am able to change the font of some <p> tags by means of using selecter.style.fontFamily = font no problem, but can not manipulate the properties of variable t for some reason.

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

0

style is a property found on HTMLElement objects but t is a String (so its style property is undefined).

If you want to style some text you get from a JS string literal, you need to put it inside an HTML Element first.

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