I set the same id for two items. Why is the second painted?
#red { color: red; } <span id="red"> red </span> no red <span id="red"> red </span> Because it is css. Theoretically, each element is checked for compliance with each selector. In this case, both elements of the selector approached.
Unlike js, where one element is issued on request, in css styles are applied to existing elements, rather than tracked, to how many elements this selector can be applied with the need to follow the appearance of such elements.
Well, yes, the markup is still invalid.
js should probably be replaced with DOM . - teranHTML DOM , and js can only work with the document model and in fact has no requirements for the uniqueness of identifiers. That is, by itself, js it has nothing to do with it at all. In this case, uniqueness is needed not in the whole document, but in a branch of a tree. - terancss , applying the rules of visual design, and js , allowing you to manipulate the structure. Therefore, talking about css and js , without affecting HTML, is somehow not entirely correct. - teranIn the case of CSS, the id behaves like a class, but in JavaScript it will be applied only to the first element:
document.getElementById("red").style.color = "red"; <span id="red"> red </span> no red <span id="red"> red </span> Source: https://ru.stackoverflow.com/questions/686605/
All Articles