Questions tagged [toggle]

To toggle a boolean variable is to switch it to its opposite state. If it is on, switch it off; if it is off, switch it on. In a desktop or web user interface, a toggle may be clickable switch or button that alternates the state of something in the application.

To toggle a boolean variable is to switch it to its opposite state. If it is on, switch it off; if it is off, switch it on. In a desktop or web user interface, a toggle may be clickable switch or button that alternates the state of something in the application.

5926 questions
65
votes
8 answers

How to toggle an element in array using JavaScript?

Here is my code for javascript for this simple task: Remove the element if it exists in an array. Add the element if it is not in an array. if(_.contains(this.types,type_id)){ var index = this.types.indexOf(type_id); …
wwli
  • 2,623
  • 6
  • 30
  • 45
64
votes
2 answers

How to toggle class using pure javascript in html

I have a
, and I want to toggle its classes on hover. Here is my code: function a(){ this.classList.toggle('first'); this.classList.toggle('sec'); } document.querySelector('#container').addEventListener('click', a ); I know there is no…
user2906766
  • 863
  • 3
  • 10
  • 12
60
votes
7 answers

jquery .slideToggle() horizontal alternative?

slideToggle does exactly what I want, only I want the slide to be horizontal. I now have an horizontalhide/show and animation on click, but I would like to have the toggle options. So that when I click on the active link, it will play the animation…
ThomasCS
  • 717
  • 2
  • 6
  • 11
57
votes
7 answers

How to add the text "ON" and "OFF" to toggle button

On my project I wanted to add a text on my existing toggle code.So I wanted like this, When toggles ON it should display the text "ON" and display the "OFF" text if toggles off. I can't change it to other toggle because it's already have a backend…
KennethLazos
  • 731
  • 2
  • 6
  • 8
55
votes
7 answers

Toggle visibility property of div

I have an HTML 5 video in a div. I then have a custom play button - that works fine. And I have the video's visibility set to hidden on load and visible when the play button is clicked, how do I return it to hidden when the play button is clicked…
tfer77
  • 786
  • 1
  • 6
  • 16
48
votes
7 answers

Toggle show/hide on click with jQuery

I got a div element, so when I click on it, another div which is hidden by default is sliding and showing, here is the code for the animation itself: $('#myelement').click(function(){ $('#another-element').show("slide", { direction: "right" },…
Cyclone
  • 14,839
  • 23
  • 82
  • 114
46
votes
4 answers

How to start off my jquery toggles as hidden?

I have some code which displays three images and a respective div under each image. Using the jquery .toggle function I have made it so each div will toggle when the image above it is clicked. Is there any way to make it so the divs start off as…
John
  • 1,556
  • 4
  • 26
  • 42
40
votes
14 answers

How to toggle between two values?

I want to toggle between two values in Python, that is, between 0 and 1. For example, when I run a function the first time, it yields the number 0. Next time, it yields 1. Third time it's back to zero, and so on. Sorry if this doesn't make sense,…
Yngve
  • 743
  • 4
  • 10
  • 15
37
votes
12 answers

How to change css of tag from an outside link

I have a menu in a tag called sf-menu. I need the visibility to change to none when the link is clicked and toggled back when clicked again. Can I achieve this with CSS only or do I need JavaScript? Hoping someone can help me with an…
Erik
  • 5,701
  • 27
  • 70
  • 119
30
votes
5 answers

Toggle between two classes in jQuery

I'm trying to modify the icons for the jQuery UI portlets. Rather than have a plus to minimize and a minus to expand, I wanted to switch them. I've only had limited success with it where the first time to click the minus it flips to a plus, but…
CAbbott
  • 8,078
  • 4
  • 31
  • 38
29
votes
11 answers

slideToggle JQuery right to left

i'm new in JQ i have this script i found on the internet and its do exactly what i need but i want the sliding will be from the right to the left how can i do it? please help this is the code
benjo
  • 351
  • 1
  • 5
  • 11
28
votes
4 answers

jQuery toggle animation

I have this jQuery: $(document).ready(function() { $("#panel").hide(); $('.login').toggle( function() { $('#panel').animate({ height: "150", padding:"20px 0", backgroundColor:'#000000', opacity:.8 },…
Kevin Brown
  • 12,602
  • 34
  • 95
  • 155
28
votes
4 answers

link with href="#" scrolls page to top when used with jquery slidetoggle

Possible Duplicate: How do I stop a web page from scrolling to the top when a link is clicked that triggers javascript? I'm using jquery's slidetoggle to show/hide divs. the element that controls the sliding is a text link ( some text inside…
samoyed
  • 881
  • 4
  • 13
  • 25
28
votes
2 answers

Equivalent of deprecated jQuery Toggle Event

jQuery's Toggle Event function has been removed as part of version 1.9. I was using this function like so: $('#example').toggle(function() { do stuff }, function() { do stuff }); What would be the best way to reproduce this functionality…
Alec Rust
  • 10,532
  • 12
  • 48
  • 63
27
votes
7 answers

Jquery, hide & show list items after nth item

Say I have an unordered list, like so:
  • One
  • Two
  • Three
  • Four
  • Five
How would I, using JQuery, hide the last 2 list items and have a 'show more' link there, so when clicked upon,…
Keith Donegan
  • 26,213
  • 34
  • 94
  • 129