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?
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.


Open in new window

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

          $('#list').append('<li data-keyValue= "' + list_keyValue + '">'  + list_dataValue + '</li>');
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
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.