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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:36:37+00:00 2026-06-08T20:36:37+00:00

I have a selection menu using toggleClass(). to see which menu options were selected:

  • 0

I have a selection menu using toggleClass(). to see which menu options were selected:

$('.img1, .img2, .text1, .tex2').click(function() {
    $(this).toggleClass('selected');
});

The way my selection menu works is that if two elements have the class selected then something will happen. For example:

if ( $('.img1').hasClass('selected') && ('.text1').hasClass('selected') ) {
    // do something
}

This all works perfectly however I want to disable the user from picking two imgs or two texts. The way I want to do this is just have the first selected element be removed from the selected class and the second selected element stay selected. For example:

if ( $('.img1').hasClass('selected') && ('.img2').hasClass('selected') ) {
        // remove selected from the element that was first clicked and keep selected on the element that was clicked second
}

What would be the best way of achieving this? Thanks in advance.

  • 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-08T20:36:39+00:00Added an answer on June 8, 2026 at 8:36 pm

    Try:

    $('.img1, .img2').click(function() {
        $('.img1, .img2').removeClass('selected').filter(this).toggleClass('selected');
    });
    $('.text1, .text2').click(function() {
         $('.text1, .text2').removeClass('selected').filter(this).toggleClass('selected');
    });
    

    Separating your click events will ensure only one of each type of item is selected.

    Also, make sure you aren’t doing $('this').

    It should be $(this).

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

Sidebar

Related Questions

I have a Menu object (set as the DataContext) which contains many Options (Menu.Options)
I have a selection for some items using a spinner widget. At the moment
I have Spatial Selection implemented on Map in my Web Application, which selects the
I have in XAML 3 menu items defined (using WPF-MDI): <MenuItem Header=_Generic Name=Generic ToolTip=Generic
Quick question - I'm using the menu function in R with graphics=TRUE . For
Iam working on a game in which I have created a horizontal scrolling menu
I'm using a jquery mobile custom select menu for a selection of countries. I
I have a menu in MainViewModel, now on selection of a particular menuItem I
Using an unordered list for my menu .. I've got the selection for the
I have a requirement to create a simple menu/selection design tool - the idea

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.