Code locality has some advantages and some disadvantages.
A “perfect” website has things cleanly separated out between style, logic, and DOM, but that does cause cases where you might have to edit three files every time you change a single widget of your website. Neglecting to do that can leave dead or incorrect code just because the issues do not inherently present themselves to you.
Yes, a perfectly principled programmer would do it right… but have you worked with other people before? They’re not necessarily very reliable.