It is not recommended to have multiple elements with the same id in HTML. However, if you want to select all the elements with the same id using JavaScript, you can use querySelectorAll
method to select all the elements with that particular id and loop through them to perform any operations.
Here's an example code snippet that selects all the elements with the same id "example_id" and logs their innerHTML values to the console:
143 chars6 lines
Alternatively, you can also use getElementById
method to select only the first element with that particular id:
88 chars4 lines
gistlibby LogSnag