Answers for "js query select attribute"

8

javascript select element with attribute

document.querySelectorAll('[attrname="value"]');
Posted by: Guest on June-02-2020
0

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>
Posted by: Guest on March-14-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language