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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:40:47+00:00 2026-06-13T23:40:47+00:00

I have the following HTML structure: <div id=settings-choose> <a href=#setting1 class=setting-tab> <div class=content> <div

  • 0

I have the following HTML structure:

<div id="settings-choose">
    <a href="#setting1" class="setting-tab">
        <div class="content">
            <div class="icon setting1-off"></div>
            <div class="label">Setting 1</div>
        </div>
    </a>
    <a href="#setting2" class="setting-tab">
        <div class="content">
            <div class="icon setting2-off"></div>
            <div class="label">Setting 2</div>
        </div>
    </a>
    <!-- more .setting-tab elements -->
</div>

Whenever I click on one of the .setting-tab elements, I want to:

  1. Add the class .selected to that .setting-tab element (and remove it from the others)
  2. Replace the “-off” part of the class on its child .icon element with “-on” (and flip all of the others to “-off“)

I can do #1 successfully, but not #2. Here’s what I have:

$("#settings-choose .setting-tab").click(function(){
    $("#settings-choose .setting-tab").removeClass("selected");
    $(this).addClass("selected");

    $("#settings-choose .setting-tab").each(function(){
        var icon = $(this).find(".icon"),
            state = icon.attr("class");

        if (!($(this).hasClass("selected"))){
            state.replace("-on", "-off");
        } else {
            state.replace("-off", "-on");
        }
    });
});

This correctly adds the .selected class to whichever .setting-tab element was clicked and removes it from the others…

<a href="#setting1" class="setting-tab selected">...</a>
<a href="#setting2" class="setting-tab">...</a>

But the class of the .icon element doesn’t change…

<a href="#setting1" class="setting-tab selected">
    <div class="content">
        <div class="icon setting1-off"></div>
        <div class="label">Setting 1</div>
    </div>
</a>

I don’t get any errors in the console, just…it doesn’t change.

Any ideas where I’m going wrong?

  • 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-13T23:40:48+00:00Added an answer on June 13, 2026 at 11:40 pm

    Quick answer is you forgot the assign value for class just replacing a text in the variable.

        if (!($(this).hasClass("selected"))){
                icon.attr("class", state.replace("-on", "-off"));
            } else {
                icon.attr("class", state.replace("-off", "-on"));
            }
    

    but you can make other changes to for example

    $("#settings-choose .setting-tab").removeClass("selected");
    

    instead

    $("#settings-choose .selected").removeClass("selected"); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have following HTML structure: <div class=container> <div class=sidebar></div> <div class=content></div> <div class=subscript></div> </div>
I have the following html structure: <div class=container> <div class=header></div> <div class=sidebar></div> <div class=content-loading></div>
I have the following HTML structure <div class=store><a href=#>GERMANY</a></div> <div class=store_details> <p>Stores in Germany</p>
I have the following HTML structure: <div class=outer> <div class=inner> <a href=#/> <a href=#/>
I have the following html structure: <div class=divClass> <a class=aClass href=#> <img src=xxxx.jpg <span
I have the following html structure: <div class=event tiny> <a href=/whatever>Something</a> </div> And I
I currently have the the following HTML structure: <div class=article-preview> <h1><a href=>Title</a></h1> <a class=pic-link
I have the following html structure <div id=rn_answertext> <p>asdasdasdas</p> <p>asdasdasdas</p> <p>asdasdasdas</p> <h3>asdasdasdas</h3> <div id=test>Content
I have the following HTML structure <div id=el> ... <div> ... <div class=x> ...
I have the following HTML structure: <div><a href=link1>blah</a></div> <div><a href=link2>blah</a></div> <div><a href=link3.swf>blah</a></div> <div><a href=link4>blah</a></div>

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.