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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:13:55+00:00 2026-05-16T04:13:55+00:00

I’m trying to find a simple way to attach click events to an element,

  • 0

I’m trying to find a simple way to attach click events to an element, which is quite easy for the 1st and 2nd click events.. But, what I am trying to accomplish is a three click Toggle.

1st click = addClas(‘one’);
2nd click = removeClass(‘one’).addClass(‘two’);
3rd click = removeClass(‘two’).addClass(‘three’);
next click would == 1st click and through the loop again..

I’m using a simple div and applying styling through CSS, to change the elements background position – all pretty typical and easy.. and is cake to do for a toggle() or click() event.. but I can’t figure out for the life of me how to handle the 3rd click ! 😀

Here is my markup, for example purposes:

<div class="tri-swtich" id="switch"></div>

Any help is greatly appreciated !!

UPDATE:
I’ve got something that works.. but, IMHO it’s ugly and messy.. there’s got to be a cleaner, more concise way of doing this:

$(".tri_switch").click(function(){
    var this_id = $(this).attr("id");

    if( $(this).hasClass("one") ){                  
        $("input#user_"+this_id).attr('checked','checked');
        $("input.tri_switch_radio").not("#user_"+this_id).removeAttr('checked');
        $(this).removeClass('one').addClass('two');
        $("span.tri_switch_checked").text('User');
    }
    else if ( $(this).hasClass("two") ){
        $("input#admin_"+this_id).attr('checked','checked');
        $("input.tri_switch_radio").not("#admin_"+this_id).removeAttr('checked');
        $(this).removeClass('two').addClass('three');
        $("span.tri_switch_checked").text('Admin');

    }
    else if ( $(this).hasClass("three") ){
        $("input#readonly_"+this_id).attr('checked','checked');
        $("input.tri_switch_radio").not("#readonly_"+this_id).removeAttr('checked');
        $(this).removeClass('three').addClass('one');
        $("span.tri_switch_checked").text('Readonly');

    }
//  alert(this_id);
});
  • 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-16T04:13:56+00:00Added an answer on May 16, 2026 at 4:13 am

    Yup @Codler, toggle() can take more than the default two parameters. Just throw in the third parameter:

    $('#element').toggle(function(){
      $(this).addClass('one');
    },
    function(){
      $(this).removeClass('one').addClass('two');
    },
    function(){
      $(this).removeClass('two').addClass('three');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

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.