how to get a custom data value from a highlighted class element using jquery?

how to get a custom data value from a highlighted class element?

this works,

$("#list li.highlight").index();

but this does not work...

$("#list li.highlight").attr("data-keyValue"); <--- is this possible with another syntax for this to work?
areyouready344Asked:
Who is Participating?
 
WizardOfOgzConnect With a Mentor Commented:
if you have HTML like this:

<li id="foo" data-keyValue="bar">

Open in new window


You want to use the jQuery data() function.

jQuery("#foo").data("keyValue")

Open in new window


But please also note Sudaraka's comment, because you need to iterate if your selector is returning multiple elements.
0
 
zappafan2k2Commented:
Can you provide the markup for the list item?
0
 
areyouready344Author Commented:
the list item make is this:

          $('#list').append('<li data-keyValue= "' + list_keyValue + '">'  + list_dataValue + '</li>');
                  
0
 
Sudaraka WijesingheWeb Application ProgrammerCommented:
If you have more than one .highlight items, you may need to use each command.

See if this is what you are looking for http://jsfiddle.net/MAbz8/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.