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

341
Visualizações
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 à 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