2

I'm giving a JavaScript course, and one of my students came up with a weird syntax that works but I don't understand why. I understand what it does, but would like to know if it is part of the JavaScript standard to react this way, or if it's a Firefox "glitch". The question was simply to have a paragraph turn green or red depending if the mouse is over another paragraph. His answer was:

 <p id ="p1">a text</p>
 <p onmouseover = "p1.style.color = 'red';"
    onmouseout = "p1.style.color = 'green';">another text</p>

What I find strange is the "p1.style" part. What is p1? I understand that it is the <p id="p1">. But does JavaScript automatically create an object for every ID?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • It's a glitch that became a standard. [Recommend not to use it](https://stackoverflow.com/q/25325221/1048572). – Bergi Mar 19 '17 at 17:21

0 Answers0