Take a look at this awesome website for the City of New York:
There’s so much we can do! Click on the arrows at the left and right to see other top headlines! Click on “Select Language” and see a list of all the languages available for translating the page! Hover over “NYC Resources” or “311″ or “Office of the Mayor” or any of the other links across the navigation bar, and watch their background color change from white to black (and text color from black to white)!
The answer lies in the Document Object Model, or DOM. When the web browser receives the website it requested from the server, it takes the lowly HTML file and converts each element into an object, which holds the attributes and values of that element as key-value pairs, and also holds information like the parent of the element (was it nested within another HTML element?) and its position among its “siblings” (is it the second element of a bulleted list? the fifth?).