Native JS Examples
Get NodeList of elements
var elem = document.querySelectorAll('[data-id="container"]')
html: <div data-id="container"></div>
Get the first element
var firstElem = document.querySelector('[id="container"]')
html: <div id="container"></div>
Target a collection of nodes which returns a nodelist
document.getElementById('footer').querySelectorAll('[data-id]')
html:
<div class="footer">
<div data-id="12"></div>
<div data-id="22"></div>
</div>
Get elements based on multiple (OR) data values
document.querySelectorAll('[data-section="12"],[data-selection="20"]')
html:
<div data-selection="20"></div>
<div data-section="12"></div>
Get elements based on combined (AND) data values
document.querySelectorAll('[data-prop1="12"][data-prop2="20"]')
html:
<div data-prop1="12" data-prop2="20"></div>
Get items where the value starts with
document.querySelectorAll('[href^="https://"]')
$('*[data-customerID]')
You can use it with e.g.$('*[data-customerID]').each( function() { ... });
– Vernitavernoleninsk$('[data-customerID]')
– Prase