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

  • SEARCH
  • Home
  • 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 6871063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:45:35+00:00 2026-05-27T03:45:35+00:00

I am trying to use data() for the first time. I have a list.

  • 0

I am trying to use data() for the first time. I have a list. I want to attach info to the li elements

My html is basic. I am not using ids for anything but the div container. This is done to allow multiple ul on the page without having id conflicts.

html

 <div id="container">
    <ul> 
        <li><input type="checkbox"></input><label>Radio</label></li>
        <li><input type="checkbox"></input><label>Cable</label></li>
    </ul>
 </div>

In my jquery I want to find the li elements of the container and attach a name corresponding to the text.

//BaseElement is my div
$(this.BaseElement).find('li').each(function () {
     var key = $(this).text();
     if (key == "Radio")
         $(this).data({ 'name' : 'Radio' });
     if (key == "Cable")
         $(this).data({ 'name' : 'Cable' });
});

I am firing a function base off checkbox selection or label click. This may not be the most efficient way of doing that but it works (not the data part but the function firing)

$(this).find('li input[type="checkbox"]').change(function () {
     $.data($(this).parent().get('name'));
 });

$(this).find('li lable').click(function () {
     $.data($(this).parent().get('name'));
});

There is more going on with the jquery in the page then this code, but this should be all that’s necessary to see what is occurring.

  • 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-05-27T03:45:35+00:00Added an answer on May 27, 2026 at 3:45 am

    get is a jQuery AJAX method. You should replace get by data:

    $(this).find('li input[type="checkbox"]').change(function () {
         $.data($(this).parent().data('name'));
     });
    
    $(this).find('li lable').click(function () {
         $.data($(this).parent().data('name'));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use mysqli for the first time because i have some
I'm trying to use Uploadify for the first time. I have no issues with
I'm trying my first very basic Facebook app using php and have stumbled upon
I'm trying to use Haskells Data.Heap module, but I'm incapable of even using it
I'm trying to use NHibernate for data access, and I have 2 simple entities
I'm trying to use a QTreeView for the first time with QAbstractItemModel and instantly
I am using Core Data for the first time and was just curious if
I'm just beinning basic data driven ASP.NET webforms design. I have the first part
hii its the first time i use database in c#. i am trying to
Its y first time trying to use NSData and Gamekit. So was wondering am

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.