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

349
Vistas
How can I change the style of last element in a list?

i have a function and event listener and inside them there are other functions and event listeners and so on. it works fine but for example if i want to change only the last element the code doesn't work (it doesn't throw any error or anything just straight up does nothing)

bear in mind that i want to get the last element of a <ul> that's being created in DOM by javascript

for example

function fonter () {
    text.style.fontSize = "20px";
    text.style.fontFamily="cursive";
}
font.addEventListener("click" , fonter);

this works perfectly fine but the problem is it changes the font of every element but for example if i change it to

  text.lastChild.style.fontSize = "20px";

it does nothing. have it in mind that if i console log text.lastChild it shows the last child.

so 2 questions here . why doesn't this work even thou when i console log it , it shows up , and 2nd what's the best way to change like style or innertext or ... of last child in DOM? thanks

thanks

about 4 years ago · Juan Pablo Isaza
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