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

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, 08:46 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
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.
johnsmith153 is offline   Reply With Quote
Old 12-12-2012, 09:13 AM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
$('[data-test]')

http://api.jquery.com/has-attribute-selector/
__________________
"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
AndrewGSW is offline   Reply With Quote
Old 12-12-2012, 11:35 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
Excellent. Thanks. So simple.
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 12:02 AM.


Advertisement
Log in to turn off these ads.