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?
Asked
Active
Viewed 526 times
2

vtacreative
- 618
- 8
- 22
-
use callback function of toggle – rahularyansharma Apr 11 '13 at 05:55
2 Answers
0
$('#toggleButton2').click(function () {
$('#disclaimer').toggle('slow', function () {
if ($('#disclaimer').is(':visible')) {
alert('hide');
$('#toggleButton2').val('Hide');
} else {
alert('Show');
$('#toggleButton2').val('Show');
}
});
});
SAME BUT SHORT
$('#toggleButton2').click(function () {
$('#disclaimer').toggle('slow', function () {
$(this).is(':visible') ? $('#toggleButton2').val('Hide') : $('#toggleButton2').val('Show')
});
});

rahularyansharma
- 11,156
- 18
- 79
- 135
-
It's actually not the same, your first example throws popups, the second one achieves the desired result, but, thanks! – vtacreative Apr 11 '13 at 06:15
-
alert are just to show that this time callback function called , anyways i am happy its works for you . – rahularyansharma Apr 11 '13 at 06:15
-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!
-
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
-
2Searching `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