jQuery onclick toggle class name

0 votes

Using jQuery, how do I toggle classA to classB on click going from:

<a class="switch" href="#">Switch</a>
<div class="classA"></div>


$('.switch').on('click', function(e){
    $('.classA').removeClass('classA').addClass('classB');
    e.preventDefault();
};

How do I toggle the class, instead of just replacing it like I'm doing here?

Aug 22, 2022 in Web Development by gaurav
• 23,260 points
376 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Web Development

0 votes
0 answers

jQuery (Greasemonkey) : Sorting images by name/class

Here is code from HTML. I would ...READ MORE

Aug 19, 2022 in Web Development by gaurav
• 23,260 points
343 views
0 votes
1 answer

JQuery - Change event using element by name

How to trigger a event with event ...READ MORE

answered Jun 28, 2022 in Web Development by rajatha
• 7,680 points
2,977 views
0 votes
1 answer

jQuery show() won't turn Bootstrap d-none class visible

When you not sure how your element ...READ MORE

answered Jun 27, 2022 in Web Development by rajatha
• 7,680 points
2,611 views
0 votes
0 answers

JQuery use variable by name of divID

Just a quick question, that I cannot ...READ MORE

Jul 19, 2022 in Web Development by gaurav
• 23,260 points
1,066 views
0 votes
0 answers

I cant hide divs which has spesific class with Jquery

I changed my code to below code ...READ MORE

Jul 20, 2022 in Web Development by gaurav
• 23,260 points
288 views
0 votes
0 answers

jQuery exclude elements with certain class in selector

I want to setup a click event ...READ MORE

Jul 20, 2022 in Web Development by gaurav
• 23,260 points
1,310 views
0 votes
1 answer

How to use jquery with asp.net ajax?

If you weren't aware, Microsoft is planning ...READ MORE

answered Oct 15, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
746 views
0 votes
1 answer

Is 'sparkline' a method?

I suggest you to check 2 things That jquery.sparkline.js is actually ...READ MORE

answered Nov 9, 2018 in Apache Spark by Frankie
• 9,830 points
1,269 views
0 votes
1 answer

What is jQuery?

Hey, jQuery is a fast and concise JavaScript ...READ MORE

answered Feb 14, 2020 in JQuery by kartik
• 37,520 points
1,314 views
0 votes
1 answer

Error: Global Variable is not accessable to local function

Hey kartik, A variable declared outside a function has a ...READ MORE

answered Feb 19, 2020 in PHP by Niroj
• 82,840 points
1,086 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP