<p id="id1">1st paragraph with id = id1</p>
<p id="id1">2nd paragraph with id = id1 (incorrect use)</p>
<button onclick="getElement()">Get element</button>
<script>
function getElement() {
// selecting element by its id
let element = document.querySelector("#id1");
element.style.background = "lightgreen";
}
</script>
The querySelector method lets you retrieve an element using a CSS selector query. The getElementById method retrieves an element by its DOM ID.