Questions tagged [toggleclass]

The toggleClass method in jQuery provides a mechanism for adding or removing a class or list of classes by name from selected elements.

The toggleClass method in jQuery provides a mechanism for adding or removing a class or list of classes by name from selected elements.

For example, if a CSS class has been applied to a div and the user wishes to remove this class from the div, the following code would accomplish this task:

theDiv.toggleClass('theClassName');

Documentation for the toggleClass method can be found in .toggleClass().

503 questions
4
votes
2 answers

toggle class based on accordion visibility

So I really don't think this should be this hard but I have been working on it for a few hours and have scoured Stack, which has helped get me to this point but not all of the way to where I need to be. I have an accordion for an FAQ page. This…
JSum
  • 597
  • 9
  • 20
4
votes
2 answers

Dynamically Changing Class on Window Resize

What I'm doing and have spent many hours attempting today is add a class to an element when the window is resized using the value of the viewport. Basically, I want to add the class as the viewport value in on page load, then change that…
Jarod Thornton
  • 401
  • 1
  • 7
  • 24
4
votes
3 answers

jquery animate() toggle without hiding the element

Is there a way to toggle a single CSS property using the animate() function without hiding it? Something like this; $(".block").animate({ 'border-width': 'toggle' }, 1000); I cannot use the toggleClass(), addClass() or removeClass(). The reason for…
Danielle
  • 243
  • 1
  • 3
  • 12
4
votes
3 answers

Toggle between 3 classes using toggleclass

I have 3 images that I want to switch between. I put each one of them in a class & change it's image in the css. I can now switch between 2 classes but when I add the third one the code doesn't work. Any class of them can be the starting one. …
Sana Joseph
  • 1,948
  • 7
  • 37
  • 58
3
votes
1 answer

Anyone else ever has this issue with jquery toggleClass?

I have a div that i'm toggling a class on click it starts off with a gold class if i call toggelClass like so $('#HomePageFavourite').toggleClass('gold grey'); what i'm left with is a div with both gold and grey classes (i would have expected the…
topwik
  • 3,487
  • 8
  • 41
  • 65
3
votes
6 answers

JQuery Using toggleClass() inside a .click() of the same class doesn't seem to work

So what I'm trying to do is sort of like the thumbs up/thumbs down voting system on youtube using jquery, implying that once a user has voted, both divs(images, doesn't matter what) will become unavailable for that specific post. So far, to do so, I…
Julz
  • 157
  • 1
  • 3
  • 9
3
votes
2 answers

jQuery: Click outside element to "close" menu that uses toggleClass to appear

I've built some navigation (for mobile web) that uses the toggleClass method in jQuery to hide and reveal the menu. Clicking on the 'MENU' icon/button toggles the class '.active' (display: hidden) on and off of the menu div. I've been desperately…
Jed
  • 33
  • 1
  • 4
3
votes
3 answers

Change class name in two class i element

I need to change class on click, in element, which has 2 classes. The first class is always "fa" and the second class "fa-minus" or "fa-plus". I need to change this second class from "minus" to "plus" and "plus" to "minus", depending on which…
divHelper11
  • 2,090
  • 3
  • 22
  • 37
3
votes
0 answers

Bug only on iPhone for a fixed submenu when scrolling

I am in the process of finalizing a fully custom, fully responsive website, per below : http://blakel11.github.io/starter-kit/app/ There is a bug with the submenu (category filter) that I cannot figure out, and only occurs in the actual (iPhone 6s…
3
votes
1 answer

Change Font Awesome Icon on Click, but return to original icon when next item is clicked

I'm using Bootstrap 3 Panel's and have appended the Font Awesome Plus and Minus icons to the panel items. I'm looking for a way using Jquery to change the plus to a minus "onClick", then when another panel item is clicked I want that minus icon to…
3
votes
3 answers

toggle a random class with jquery

the idea is having a button that, when clicked, adds a random class picking it from an array to another div. what i want is having that same button to remove any randomly added class from it when i re-click it. here's a fiddle:…
valerio0999
  • 11,458
  • 7
  • 28
  • 56
3
votes
1 answer

jquery toggleClass to just children element

i have an issue to toggleclass for just children element.
3
votes
2 answers

add or remove class on click with data- attribute

Simple jquery click toggle function here, though due to my limited knowledge and experience I'm in need of some direction. I have a set of buttons with a shared boxedBgSwitch class that each have have a uniquie data-id. I'd like to assign the…
Isaac Gregson
  • 1,999
  • 1
  • 21
  • 31
3
votes
1 answer

jquery add class on input click and remove class when click other input

I need to add a class to the input wrapper when I click on input, and remove the class when other input is clicked. I've tiyed toggleClass but it would only remove the class when the same input is clicked again. I've tried to use functions: find()…
mlclm
  • 725
  • 6
  • 16
  • 38
3
votes
3 answers

jQquery - the elements first class was changed, but jquery still calls the elements first class.

I have a problem and I really searched for answers and I asked some persons.. but no solution. I have 3 'td' elements, they all belong to a class = "moreSpace" ... so when I click on a td element.. it changes its class to "deactivateAssignments" ...…
MisterNowhere
  • 605
  • 1
  • 6
  • 13
1
2
3
33 34