Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Get all data- attributes

    How do I get all the occasions of <div data-test="value"> on a page?

    So:
    Code:
    <body>
        <div class="section" data-test="123">
            <div class="top">
    
            </div>
            <div class="bottom" data-test="123">
    
            </div>
        </div>
        <div class="section">
            <p data-test="123">
    
            </p>
        </div>
    </body>
    ...returns reference to the three occasions above and allows me to perform actions on the node they sit on.

    I know $(".section").data("test") will get it but I want to get it for all occasions on any page with any HTML and any classes.

    I tried $('body').data('test') and $('div').data('test') but nothing.

    Thanks.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Maybe you need to ask the question in the jQuery section?

    I can give you a non-jQuery, vanilla JavaScript, answer. But you don't seem to want that.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Mar 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Maybe you need to ask the question in the jQuery section?

    I can give you a non-jQuery, vanilla JavaScript, answer. But you don't seem to want that.
    Ok I'll ask in the jQuery section, but it doesn't have to be jQuery - whatever works will do.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •