Solved

Pull data element

Posted on 2014-10-23
1
89 Views
Last Modified: 2014-10-23
Trying to do a simple task of pulling the value out of the data element, which I thought would be easy, but obviously not. To simplify my issue, Ive got the following HTML code:-
<div id="divMenu">
    <div data-folderID="4" class="menuTopItem">Operational</div>
    <div data-folderID="5" class="menuTopItem">Administrative & Accounting</div>
    <div data-folderID="6" class="menuTopItem">Time Sheets</div>
    <div data-folderID="7" class="menuTopItem">Interface</div>
    <div data-folderID="8" class="menuTopItem">Setup</div>
</div>

Open in new window


And then to simply pull out the value:-
$(document).ready(function () {
    $('.menuTopItem').click(function (e) {
        alert($(this).data("folderID"));
    });
});

Open in new window


However I keep getting 'undefined', and I cannot figure out why, does anyone have any ideas?

Ive put it onto jsFiddle in the hope someone can point out the error of my ways.

Thank you in advance
0
Comment
Question by:tonelm54
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40399555
use:
data-folderid
and :
alert($(this).data("folderid"));

no uppercase, right.
More infos here :
http://www.w3.org/TR/2011/WD-html5-20110525/elements.html#embedding-custom-non-visible-data-with-the-data-attributes
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now