Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript querySelector - By Attribute

<p title="1st item with title">Paragraph with 1st title.</p>
<p title="2nd item with title">Paragraph with 2nd title.</p>
<button onclick="getElement()">Get element with title attribute</button>

<script>
  function getElement() {
    let element = document.querySelector("[title]");
    element.style.background = "lightgreen";
  }
</script>
Source by www.tutorialstonight.com #
 
PREVIOUS NEXT
Tagged: #JavaScript #querySelector #By #Attribute
ADD COMMENT
Topic
Name
6+3 =