The code creates a numbered footnote system for a webpage. The numbered buttons such as [1], [2], and [3] appear within the text like traditional footnote references. When the user moves the mouse over one of these numbers, the corresponding footnote appears as a small green pop-up box.
The HTML provides the structure of the page. The .footnote elements at the beginning contain the actual footnote text, while the .btn buttons placed throughout the paragraphs act as references to those footnotes. The buttons use IDs from 0 to 10, while their visible labels run from [1] to [11]. The stylesheet styles.css and JavaScript file scripts.js are loaded externally.
The CSS controls the appearance and positioning. .page creates a centered, 600-pixel-wide document-like container with a border and shadow. The .btn class makes the footnote references look like small blue links rather than normal buttons. The .footnote class initially hides each footnote using display: none, and the :nth-child() rules give each footnote a specific position on the page. When JavaScript changes display to block, the footnote becomes visible at that predefined position.
The JavaScript connects each numbered button to the footnote with the same position in the two NodeLists. querySelectorAll(".btn") collects all the numbered buttons, while querySelectorAll(".footnote") collects all the footnotes. The forEach() loop goes through the buttons and uses the index to identify the matching footnote. For example, button 0 controls footnote 0, button 1 controls footnote 1, and so on.
When the mouse moves over a button, the mouseover event changes the corresponding footnote's display property from none to block, making it visible. When the mouse leaves the button, the mouseout event changes it back to none, hiding it again. In effect, the user can hover over [1] to see footnote 1, hover over [2] to see footnote 2, and continue in the same way through [11].
To use the code, place the HTML in your webpage, put the CSS in a file called styles.css, and put the JavaScript in scripts.js. Both files need to be in the appropriate location specified by the HTML. You can then replace the placeholder footnote text with your own content and adjust the top and left values in the CSS if you want the pop- ups to appear in different locations.