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
3
votes
5 answers

Three-way toggling of two states (Javascript or jQuery)

I am working on a page that will show prices in a choice of currencies (euros, pounds or dollars). My aim is to display the price in euros first, keeping the pound and dollar prices hidden.

TrapezeArtist
  • 777
  • 1
  • 13
  • 38
3
votes
4 answers

Toggle class with animation

I want to have something like this : $('#fo').toggleClass('tra', 'slow'); I know that i can achieve this with jQuery UI but i'm looking for a faster and smaller solution because i don't wanna integrate in my site another 20-90 kb
Code
  • 83
  • 1
  • 2
  • 10
3
votes
2 answers

JQuery UI (effects core) addClass/removeClass on one element with multiple selectors...but there's a catch

Thanks for taking a look. I'm trying to used the jQ UI addClass / remove Class methods to expand an hr element upon clicking preceding sibling divs. jQ UI effects core enables smooth animated transition between two classes:…
3
votes
2 answers

How to close other open elements when one is opened in jQuery?

I know. The title was a bit....hard to understand. I will see what I can do to help you understand it. Basically, what I've done for my personal site is the main navigation as the body of the web page. And when a link is clicked, it loads some…
user1316498
2
votes
2 answers

jquery toggleClass not working

For some reason the toggleClass function does not seem to be working. I have a table row with a class "nodrag" - being used with tableDnD plugin: When I click a link I want to toggle…
Henry Ing-Simmons
  • 1,362
  • 5
  • 18
  • 25
2
votes
2 answers

using addClass or toggleClass with JQuery inside a click method does not work? bug?

This seems very simple.. and still it does not work correctly. I got it working if you put the class .normal above the .hightlight.. but i don't alter the style here.. only the position. This does not make any sense.. I can't seem to paste the html…
chriscross
  • 41
  • 1
  • 4
2
votes
2 answers

Can you make toggleClass animation without jQuery UI?

Can I make this: http://jqueryui.com/demos/switchClass/default.html without jQuery UI? Basically I have a simple site which the body has a class named: '.bgone'. .bgone has background color: #ccc and I want to toggle the .bgtwo of which…
jQuerybeast
  • 14,130
  • 38
  • 118
  • 196
2
votes
1 answer

JQuery: Toggle class on an anchor while scrolling

I have a html-document with a main navigation and a subnavigation consists of anchors. What I'm trying is to toggle a class to the anchor (subnavigation) while scrolling through the document. With JQuery i tried the following: $(function() { …
2
votes
4 answers

jQuery UI ToggleClass CSS hover

I have a website at http://www.presentbladet.se (unfinished). When I hover the "Test product" a magnifying glass appears. So far, so good. Fade in - but keep hover in CSS I want the transition to be smooth with a fade in effect. I still want to keep…
Jens Törnell
  • 23,180
  • 45
  • 124
  • 206
2
votes
5 answers

jquery toggleClass, removeClass

Solved: Thanks to eveyrone that tryed to help Added this code and it worked: $(function() { $( ".itemContainer" ).click(function() { $(this).toggleClass( "showtheitem", 800 ), $(this).prev(".itemContainer").toggleClass("hide"), …
andy
  • 177
  • 2
  • 12
2
votes
2 answers

jquery toggle accordian without plugin

Hi have two content sections and i only want 1 open at a time. They both collapse and open based on clicking the headings. I have it currently working where they are independent of each other but i am looking to have them hide the other when it is…
estern
  • 460
  • 3
  • 8
  • 26
2
votes
4 answers

css toggleClass in jquery?

i want to toggle between designs /* Heart sign */ .fav { margin-left: 0px; color: #0099CC; padding-left: 20px; padding-right: 4px; padding-bottom: 4px; -moz-border-radius: 5px; border-radius: 5px; background:…
getaway
  • 8,792
  • 22
  • 64
  • 94
2
votes
2 answers

jQuery - Remove class from any
  • that wasn't just clicked
  • Lets say I have list like this...
    • One
    • Two
    • Three
    ...and I want to be able to toggle class in the li's... $( "li" ).click(function() { $( "li" ).toggleClass(…
    Joonas
    • 7,227
    • 9
    • 40
    • 65
    2
    votes
    1 answer

    Toggle classes with jQuery by clicking button and clicking other element than selected

    I'd like to toggle the drawer with the 'drawer-toggle'-button, as shown in the snippet. The only problem is that when the drawer is opened, I want to close it also with by clicking outside the .drawer-div. Anyone could help me with this one? There…
    Falch0n
    • 305
    • 1
    • 3
    • 11
    2
    votes
    4 answers

    why does changing of class of a element distorts the view?

    I am trying to change a class of a element and my view gets distorted? How do I solve it. I have created the fiddle for the same Jsfiddle Issue Description: I have a custom textbox. I have a reference value at top left corner of it. If I enter…
    Chetan
    • 4,735
    • 8
    • 48
    • 57
    1 2
    3
    33 34