jQuery Toggle State jQuery Toggle State jquery jquery

jQuery Toggle State


You can check the state of the toggle in jQuery by using .is(":hidden"). So in basic code what I used:

$("#div_clicked").click(function() {  if ($("#toggle_div").is(":hidden")) {     // do this  } else {     // do that}}); # add missing closing


jQuery has two .toggle() methods:

.toggle()

Toggles each of the set of matched elements. If they are shown, toggle makes them hidden. If they are hidden, toggle makes them shown.

.toggle(even, odd)

Toggle between two function calls every other click.

In this case you want the first one. Something like this should do the trick:

$("a").click(function() {    $("#theForm").toggle();});


Here's what I used:

$(document).ready(function() {    $('#listing_position').click(function() {    var div_form = $('#listing_position_input');        if (div_form.hasClass('hide')) {           div_form.removeClass('hide');        } else {          div_form.addClass('hide');        }    });  });