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 3301130
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:43:22+00:00 2026-05-17T20:43:22+00:00

Greetings, Being new to jQuery’s syntax, I find myself being a bit thrown off

  • 0

Greetings,

Being new to jQuery’s syntax, I find myself being a bit thrown off when writing up some code. So while I realize my issue is very likely a logic issue, I’m still have issues finding it because of the syntax that I’m not used to.

I have a series of <li> tags that have an <input type="checkbox"> within each of them. When the page is refreshed, the checkboxes remain checked, however the <li> needs to keep the class of .grey attached still, but it loses it. Here is the code I’m trying to use at the moment to fix this issue:

$('#servemod').ready(function() {
    $('#servemod').find('li').each( function() {
    if ($('li').find('input:checkbox').attr('checked')==1) {
        /*alert($(this).find('input:checkbox'));*/
        /*alert($('li').find('input:checkbox').attr('checked'));*/
            $(this).addClass('grey');

    }
    });
});

I’m currently using the alert boxes to tell me exactly which part of the DOM the jQuery is currently looking at, and it seems okay. But the problem is that even with the loop, it only seems to test the first <li>‘s checked state. If the first one is checked, the loop goes through and turns ALL <li>‘s to blue. If the first one is not checked, it does nothing. I’m positive this is something very basic, but I’ve been at this for hours and I’m just not seeing it. Any help would be greatly appreciated.

The full code to the html section (with a lot of fluff pulled out)

<div id="servemod">
   <ul>
      <li><input type="checkbox"><p>box 1</p>
      <li><input type="checkbox"><p>box 2</p>
   </ul>
</div>

The css value for grey is just a colour change to blue.

  • 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-17T20:43:23+00:00Added an answer on May 17, 2026 at 8:43 pm
        $(document).ready(function() {
          $('#servemod ul li input:checked').each( function() {
            $(this).closest('li').addClass('grey');
          });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, I'm trying to find a way to 'unbind' a socket from a particular
Greetings! I'm working on wrapping my head around LINQ. If I had some XML
Greetings, I'm trying to find either a free .NET library or a command-line executable
Greetings, The VBA code below will create an Excel QueryTable object and display it
Greetings! I'm new to WCF and I thought it would be similar to ASP.NET
greetings, im am new to programming and at the moment developing a clone of
Greetings all, I’m working on a C# program that requires being able to get
Greetings, I am trying to play some audio files without holding up the GUI.
Greetings, everyone. I consider myself to be an intermediate developer, but, to be candid,
Greetings, I am writing a short simple script, but has became too crowded. Stuff

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.