Solved

Pull data element

Posted on 2014-10-23
1
97 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why is my angular function works in  Android and Windows but not in iOS? 7 51
Javascript_Set_dropdown_value 7 34
Javascript Form Change 5 23
Jquery 2 13
I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
The viewer will learn how to dynamically set the form action using jQuery.
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)

832 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