Access our premium support and let us know your problems, we will help you solve them.

0
No products in the cart.

Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: Selecting element by data attribute with jQuery #9349
    blanketoxin
    Participant

    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://"]')
    
Viewing 1 post (of 1 total)