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

340
Views
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
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!