I have a div which contains settings and options on an account management page.
$(\"#moreOptions\").slideToggle(\'slow\');
if ($(\"#moreOptions\").is(\":visible\
You need to use the callback function. By the time the if statement is evaluated the slideToggle will not have completed and you will get incorrect results.
$("#moreOptions").slideToggle('slow', callbackFn);
function callbackFn(){
var $link = $("#lnkMoreOpt");
$(this).is(":visible") ? $link.text("Less Options «") : $link.text("More Options »");
}
I think this code will work
$('#element').toggle('slow', function() {
if($(this).is(':hidden')) {
$(this).text('This element is hidden.');
}
else {
$(this).text('This element is visible.');
}
});
I prefer not to use separate functions because when one function does not need to be used twice, it is waste of code.. i believe this is easier to understand when someone comes to it..
$("#moreOptions").slideToggle('slow', function(){
var $link = $("#lnkMoreOpt");
$(this).is(":visible") ? $link.text("Less Options «") : $link.text("More Options »");
});