Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-12-2012, 03:53 AM   PM User | #1
johnsmith153
New Coder

 
Join Date: Mar 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
johnsmith153 is infamous around these parts
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.
johnsmith153 is offline   Reply With Quote
Old 12-12-2012, 04:52 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,168
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 12-12-2012, 08:44 AM   PM User | #3
johnsmith153
New Coder

 
Join Date: Mar 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
johnsmith153 is infamous around these parts
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.
johnsmith153 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:43 AM.


Advertisement
Log in to turn off these ads.