Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript querySelector - By ID

<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>
Source by www.tutorialstonight.com #
 
PREVIOUS NEXT
Tagged: #JavaScript #querySelector #By #ID
ADD COMMENT
Topic
Name
7+9 =