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

Thread: Data attribute

  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Data attribute

    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
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    New Coder
    Join Date
    Mar 2012
    Posts
    81
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Excellent. Thanks. So simple.


  •  

    Posting Permissions

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