I have read this on the internet -
“id” is unique in a page and can only apply to at most one element
But If I use the selector in CSS it works on every element.
index.html
<button id="button1">Button 1</button>
<button id="button1">Button 2</button>
<button id="button1">Button 3</button>
<button id="button1">Button 4</button>
style.css
#button1{
color: red;
}
output:
But js binds only the first one.
script.js
$('#button1').click((value) => {
console.log("clicked");
});
Can anyone explain, Why this is happening? And how it works?