2

So here is a show/hide toggle button that works just fine. Here is the same exact code, except that I passed the 'slow' parameter to the .toggle action. Why does the button's value toggle correctly in the first example, but not the second? Does passing the 'slow' parameter to the .toggle action somehow cause the :visible pseudo-class to return true?

vtacreative
  • 618
  • 8
  • 22

2 Answers2

0
$('#toggleButton2').click(function () {
    $('#disclaimer').toggle('slow', function () {
        if ($('#disclaimer').is(':visible')) {
            alert('hide');
            $('#toggleButton2').val('Hide');
        } else {
            alert('Show');
            $('#toggleButton2').val('Show');
        }
    });
});

JS FIDDLE LINK

SAME BUT SHORT

$('#toggleButton2').click(function () {
    $('#disclaimer').toggle('slow', function () {
        $(this).is(':visible') ? $('#toggleButton2').val('Hide') : $('#toggleButton2').val('Show')

    });
});

JS FIDDLE LINK FOR SECOND ATTEMPT

rahularyansharma
  • 11,156
  • 18
  • 79
  • 135
-1

Duplicate over here

Use the .toggle() callback on complete.

Code example from the other question

$("#moreOptions").slideToggle('slow', callbackFn);

function callbackFn(){

     var $link = $("#lnkMoreOpt");

     $(this).is(":visible") ? $link.text("Less Options «") : $link.text("More Options »");


}

Please, use search bar and google it a bit before asking. Nevertheless, hope this helped!

Community
  • 1
  • 1
Pankucins
  • 1,690
  • 1
  • 16
  • 25
  • Please, don't rudely assume I didn't spend time using search bar and Google. Seriously. I looked at a good 6-8 potential duplicates and spent decent time investigating before I posted. Folks like yourself give this site an annoying, elitist feel. – vtacreative Apr 11 '13 at 05:56
  • 2
    Searching `jquery toggle :visible` gave me an answer on the third search result. Excuse me if I insulted you by asking kindly to search harder next time, but after seeing that many questions that can be answered by simple search, every day I'm just trying to encourage people in harder investigation to keep the site cleaner and more efficient. – Pankucins Apr 11 '13 at 06:06
  • You didn't "kindly ask" anything, you talked down. If you had "kindly asked" that would have been great. Believe me, I'm all for keeping the place tidy and efficient, but sometimes a dupe gets through. Like I said, I spent decent time and didn't turn up squat. It's not like I'm asking lame subjective questions about "which framework is better for my site" ya know? – vtacreative Apr 11 '13 at 06:21