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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:49:33+00:00 2026-05-25T20:49:33+00:00

I need to swap the class in a span placed withing a link based

  • 0

I need to swap the class in a span placed withing a link based on a condition whether the link has a particular class in it or not. Tried this but it doesn’t seem to work. What am I missing?

if ($("#myLink").hasClass("dis")) {
    $("#myLink").find("span").toggleClass("uico", "uicoGR");
} else {
    $("#myLink").find("span").toggleClass("uicoGR", "uico");
}

<a href="#" id="myLink" class="dis"><span class="uico"></span></a>
  • 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-25T20:49:34+00:00Added an answer on May 25, 2026 at 8:49 pm

    The two classnames to be toggled should be passed in the first parameter, separated by spaces.

    Also, the hasClass() condition can be added to the selector.

    $('.dis#mylink span').toggleClass('uico uicoGR') ;
    

    Edit

    Reading the question again, it’s not clear that you appreciate what toggleClass() does. This function looks for all classes named and either adds them if they are not found, or removes them if they aren’t. It would appear that what you are after is adding or removing classes based on whether a third class is found. For this, just use addClass() and removeClass():

    $('#mylink').each(function() {
      if($(this).hasClass('dis')) {
        $(this).find('span').addClass('uicoGR').removeClass('uico') ;
      } else {
        $(this).find('span').addClass('uico').removeClass('uicoGR') ;
      }
    }) ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement the Copy-and-Swap Idiom for my class, because I need to
I need jquery, or css only if possible,to swap background of class to make
I need to swap out the out-of-the-box rich text editor with the Telerik editor
I need to make javascript code to swap images with option change. Here is
Need some help about with Memcache. I have created a class and want to
I have a piece of code where I need to pass the class of
In this stackoverflow question I learned that Prism/Unity is not as decoupled as I
I need to delete some objects from an ArrayList if they meet a condition
How to flip a Bitmap upside down? (I need this for loading an OpenGL
I need to pass an instance variable (self.rank) to be used by a class

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.