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

128
Views
console.log (Elemento) después de cambiar el estilo. Pero no funciona lo que esperaba. Resultado diferente en cromo local y fragmento en StackOverflow

Hice una función simple que imprime el elemento en la consola antes de cambiar el color del texto cuando hago clic en "Hacer clic".

 function addEventToTitle(){ const title = document.getElementsByClassName("title")[0]; title.addEventListener('click', changeColorOfTitle); } function changeColorOfTitle(){ const title = document.getElementsByClassName("title")[0]; console.log(title); title.style.color = "red"; } addEventToTitle();
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script defer type="text/javascript" src="test.js"></script> <title>Document</title> </head> <body> <Button class="title">Click me</Button> </body> </html>

En fragmento, funciona como esperaba. como abajo

 <button class="title">Click me</button>

Pero, cuando probé esto en local. Siempre se imprime así

 <button class="title" style="color: red;">Click me</button>

El resultado no debería implicar style="color: red; porque console.log se ejecuta antes de cambiar de color.

Mismo código pero resultado diferente, no sé cuál es el motivo de esto.

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!