0

I changed the attribute of the Node after printing it by "console.log" as you can see below.

<h1>Hello</h1>
<script>
    const h1 = document.querySelector('h1');
    console.log(h1);
    h1.style.color = 'red';
</script>

When I look at the console panel in devtool, I can see the log like below.

Result

My question is why 'style="color: red"' seems to be applied in console? Even it's before applying by the next line of the "console.log".

tono
  • 23
  • 2
  • 1
    I bet it's due to something similar to https://stackoverflow.com/questions/23429203/weird-behavior-with-objects-console-log – CertainPerformance Aug 23 '20 at 03:09
  • Try opening your console and running `document.querySelector('h1').style.color = '#123456';` after your console log and you will understand the behavior. – Elias Soares Aug 23 '20 at 03:17
  • Console objects are not snapshots...they are live objects that will display modifications made after you log them – charlietfl Aug 23 '20 at 03:21

0 Answers0