If I click another class, remove "Active"

jquery remove all classes except
jquery remove class
remove class javascript
jquery removeclass not working
javascript remove all classes
jquery add remove class
jquery add remove class onclick codepen
remove class jquery using id

I have an element with the "gmnprint" class when I click on it, adding the "active" class but when I click another element it remains.

html

<div class="gmnoprint" title="S.A.U.C." style="width: 22px; height: 35px; overflow: hidden; position: absolute; opacity: 0.01; cursor: pointer; touch-action: none; left: -294px; top: 45px; z-index: 80;"></div>
<div class="gmnoprint" title="INC." style="width: 22px; height: 35px; overflow: hidden; position: absolute; opacity: 0.01; cursor: pointer; touch-action: none; left: -288px; top: -116px; z-index: -81;"></div>

jQuery

$(document).ready(function() {
  $('.gmnoprint').click(function() {
    $(this).toggleClass("active");
  });  
});  

Instead of toggling, add and remove the classes explicitly.

 $(document).ready(function() {
    $('.gmnoprint').click(function() {
        $('.gmnoprint').removeClass('active');
        $(this).addClass("active");
    });  
    });  

jQuery Add and Remove CSS Classes, How do I delete a class in CSS media query? Change the class name of an element How to use addClass() and removeClass() to remove one class name, and add a new class name. Remove class using a function Using a function to remove a class from the selected elements. Remove several class names How to remove several class names from the selected elements.

First remove the class from all mathing elements, and then set the active class on which click is happened.

$(document).ready(function() {
  var $gmnoprint = $('.gmnoprint');
  $gmnoprint.click(function() {
    $gmnoprint.removeClass('active');
    $(this).addClass("active");
  });
});
.active {
  color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="gmnoprint" title="S.A.U.C." style="width: 50px; height: 35px;">Box I</div>
<div class="gmnoprint" title="INC." style="width: 50px; height: 35px;">Box II</div>

jQuery toggleClass() Method, Description: Remove a single class, multiple classes, or all classes from each To replace all existing classes with another class, we can use .attr( "class",  coolButton.addEventListener('click', => { shadesEl.classList.toggle('cool'); }); classList.toggle will return true if the class was added and false if it was removed: let a = shadesEl.classList.toggle('cool'); console.log(a); // true --> class was added. classList.toggle optionally takes a second argument that should evaluate to a boolean. This will force toggle to either add the class or remove it depending on the how the second argument evaluates:

$(function() {
  $('.gmnoprint').on('click', function() {
    $('.gmnoprint').removeClass('active');
    $(this).toggleClass("active");
  });
  
});
.active {
  color: #b00;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="gmnoprint" title="S.A.U.C.">Click Me</div>

<div class="gmnoprint" title="INC.">Click Me Too</div>

jQuery toggleClass(), Description: Add or remove one or more classes from each element in the set of matched elements, Toggle the class 'highlight' when a paragraph is clicked. Icon Bar Menu Icon Accordion Tabs Vertical Tabs Tab Headers Full Page Tabs Hover Tabs Top Navigation Responsive Topnav Navbar with Icons Search Menu Search Bar Fixed Sidebar Side Navigation Responsive Sidebar Fullscreen Navigation Off-Canvas Menu Hover Sidenav Buttons Sidebar with Icons Horizontal Scroll Menu Vertical Menu Bottom Navigation Responsive Bottom Nav Bottom Border Nav Links Right Aligned Menu Links Centered Menu Link Equal Width Menu Links Fixed Menu Slide Down Bar on Scroll Hide

In your click handler, you are only toggling the element that is being clicked. You also need to reset the rest of the elements on the page.

$(document).ready(function() {
    $('.gmnoprint').click(function() {
        $('.gmnoprint').removeClass('active');
        $(this).toggleClass("active");
    });  
    });  

Any other elements will have the class removed as well as toggling the element that was clicked.

How Can I Remove A Class Based Upon @media , Note: If no parameter is specified, this method will remove ALL class names from the selected elements. Syntax. $(selector).removeClass(classname,function(  Hi all, my Problem: I've got some divs with class ".tile" Every time you click on them, they should rotate 90 degrees (CSS3-Based) to perform this rotation combination of addClass, hasClass and removeClass - jQuery Forum

You could remove the class from all elements and re-apply it on the clicked one.

 $(document).ready(function() {
      $('.gmnoprint').click(function() {
        $('.gmnoprint').removeClass("active");
        $(this).addClass("active");
      });  
 });  

Fiddle:

https://codepen.io/anon/pen/Xxboxz

.removeClass(), Toggle between adding and removing the "main" class name for all <p> elements​: $("button").click(function(){ $("p").toggleClass("main"); });. Try it Yourself »  Adding to the code above, you could only create the body click event once the menu is open, that way it’s not constantly firing every time someone clicks on the page.

.toggleClass(), This post examines all the ways multiple DOM elements can be manipulated. We want to remove those .active classes when the “Deactivate” button is clicked. If a class name is included as a parameter, then only that class will be removed from the set of matched elements. If no classes are specified in the parameter, all classes will be removed. Before jQuery version 1.12/2.2, the .removeClass() method manipulated the className property of the selected elements, not the class attribute. Once the property was changed, it was the browser that updated the attribute accordingly.

jQuery removeClass() Method, These related posts were algorithmically generated and displayed here without any There are many different ways to accomplish the same goal, its however but the reason the add/remove class is more appropriate sometimes is if you have then there's the hover color, then when you click i have a div appear (​sliding  Class management. How do I remove a family member? How do I remove a teacher from my class? How do I delete my account? Can teachers download an archive of student work for their class? Why do I need to approve some families' access and not others? Students. How do I move a student post to an activity response? How do I remove a student from my

Remove a class name from multiple elements with pure JavaScript , In this tutorial you will learn how to add or remove the CSS classes from the HTML <h1> and the class .highlight to the <p> elements with class .hint on button click. Similarly, you can remove the classes from the elements using the jQuery  Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor. add Class & remove class on click, remove class from other in list too - JSFiddle - Code Playground Close