[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

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?
0
areyouready344
Asked:
areyouready344
1 Solution
 
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
 
WizardOfOgzCommented:
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now