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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:56:48+00:00 2026-06-17T10:56:48+00:00

Ok, so I really don’t think I’m structuring my JS properly, and am hoping

  • 0

Ok, so I really don’t think I’m structuring my JS properly, and am hoping someone can point me in the right direction. I don’t think sequentially naming the classes for each list item is an effective, or proper way of accomplishing this.

I have a list of checkboxes that, when clicked, need to perform two actions:

1) Toggle the class name of a div located directly below it.

2) Post via AJAX the state.

Here is my current markup:

<ol class="toolkitList">
<li>
            <label><input class="inlineCheckers" type="checkbox" id="checkers" onchange="setCheck();" /><b id="grayTitle">List Title 1</b></label>
                <i id="hiddenDiv">Div content can go here.</i>
        </li>

        <li>
            <label><input class="inlineCheckers" type="checkbox" id="checkers2" onchange="setCheck2();" /><b id="grayTitle2">List title 2</b></label>
                <i id="hiddenDiv2">Div content can go here.</i>
        </li>

        <li>
            <label><input class="inlineCheckers" type="checkbox" id="checkers3" onchange="setCheck3();" /><b id="grayTitle3">List title 3</b></label>
                <i id="hiddenDiv3">Div content can go here.</i>
        </li>

        <li>
            <label><input class="inlineCheckers" type="checkbox" id="checkers4" onchange="setCheck4();" /><b id="grayTitle4">List Title 4</b></label>
                <i id="hiddenDiv4">Div content can go here.</i>
        </li>
    </ol>

Here is my current JS:

function setCheck() {
var el = document.getElementById("checkers");

if (el.checked) {
    document.getElementById("hiddenDiv").className = "main";
    document.getElementById("grayTitle").className = "titleGray";
 } else {
    document.getElementById("hiddenDiv").className = "";
    document.getElementById("grayTitle").className = "";
 }
}

function setCheck2() {
var el2 = document.getElementById("checkers2");

if (el2.checked) {
    document.getElementById("hiddenDiv2").className = "main";
    document.getElementById("grayTitle2").className = "titleGray";
 } else {
    document.getElementById("hiddenDiv2").className = "";
    document.getElementById("grayTitle2").className = "";
 }
}

function setCheck3() {
var el3 = document.getElementById("checkers3");

if (el3.checked) {
    document.getElementById("hiddenDiv3").className = "main";
    document.getElementById("grayTitle3").className = "titleGray";
 } else {
    document.getElementById("hiddenDiv3").className = "";
    document.getElementById("grayTitle3").className = "";
 }
}

function setCheck4() {
var el4 = document.getElementById("checkers4");

if (el4.checked) {
    document.getElementById("hiddenDiv4").className = "main";
    document.getElementById("grayTitle4").className = "titleGray";
 } else {
    document.getElementById("hiddenDiv4").className = "";
    document.getElementById("grayTitle4").className = "";
 }
}

I realize I don’t have the AJAX portion of this setup yet, but I wanted to make that requirement known, as I will be adding that part into the code shortly. Thanks for any guidance you can provide!

  • 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-17T10:56:50+00:00Added an answer on June 17, 2026 at 10:56 am

    You could also apply the class to outer div

    CSS:

    .selected label b {
        color:blue
    }
    .selected i {
        color:red
    }
    

    JS:

    $(".inlineCheckers").on('click',function(){
        $(this).parents("li").toggleClass('selected',$(this).is(":checked"));
    })
    

    jsfiddle : http://jsfiddle.net/y2rHF/3/

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

Sidebar

Related Questions

I really don't understand the principle of Object Oriented Design?? So I have classes
I really don't think this has anything to do with ASP.NET MVC 2 itself,
I know that the naming conventions really don't say anything about that, but I
i really don't get how I can use a spinner just like asp.net's dropdownlist,
I really don't know how to explain this error properly... It started when I
i really don't get the point how to use predicates in zend framework 2.
I really don't understand Javascript. In PHP, I can remove quotes like this: $tags_array
I really don't understand what the issue is here, I've tried everything I can
I really don't know how to do this. I tried: #menu-right div { position:
I really don't see the point of making EJB's into web services. The first

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.