Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8287607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:05:48+00:00 2026-06-08T12:05:48+00:00

I have a ul with several items. I populate the list dynamically after page

  • 0

I have a ul with several items. I populate the list dynamically after page load using jquery. As I add each list item, I also add an “itemID” to the data of that element using the jquery “.data()” function. Something like this:

var item = $('<li>My Item Name</li>');
item.data('itemID', '123ABC456');

Later, I need a selector to determine if there is any item in my item list with a specific itemID. First I tried using:

$('*[data-itemID="123ABC456"]');

This didn’t work – and on further research, I discovered that this syntax only works if the data attribute was set in the DOM when the page was loaded; it doesn’t work if you use the “.data” jquery method dynamically.

Next I tried:

$(':data(itemID==123ABC456)');

For some reason, this doesn’t work. If I run simply $(':data(itemID)'), however, then I do get all the li elements that have an itemID in their data.

I know that the itemID attribute is set correctly, as when I call .data() on that list item I get:

Object { itemID="123ABC456"}

How can I select all elements that have an itemID of “123ABC456” in their data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:05:49+00:00Added an answer on June 8, 2026 at 12:05 pm

    http://jsfiddle.net/w28p9/1/ <– jsFiddle example showing differences with data-attribute & jquery.data()

    jQuery.data() is different than HTML5 data-NAME attributes which you are trying to search for.

    http://api.jquery.com/jQuery.data/

    jQuery.data() saves inside of the jquery element (this data is hidden from plain sight).
    Looking for [data-itemID] would work if inside of the actual had: <li data-itemID="12345"></li>.

    To retrieve and look for the actual hidden .data() try:

    // of course be more specific than just searching through all <li>'s
    $('li').each(function () {
        if ( $(this).data('itemID') === '123ABC456' ) {
            // do whatever you wanted to do with it
        } 
    });
    

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several ReorderLists on a page. Each list has items added to it
I have a listview with several items that are created dynamically, each has two
I have a list on SharePoint with several hundred items in it. I also
I have a regular control in my code with several items. <mx:List id=myList> <mx:String>Item
I have several items on memcached that should expire 24h after the creation time.
I have html that looks like this with several items <div class=item> <p class=price>$388.00</p>
I have a table with user items. Each user may have several types of
I have several items that I'm storing in the local storage. What the page
i have some Orders that can have several Items and these Items have an
Lest say that we have several pages that retrieve items from the same EntitySet.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.