$(document).ready(function () { $(".toggle_container").hide(); // report the status of h5.next visible h5nextVisible("document.ready"); console.log("====================="); // if we do the toggle before we change the text (More/Less), things are fine UNLESS we do an animation because while the animation is running the :visible reports true. // if you add "slow" or 1000 inside .toggle() this messes up the timing - try it $("h5.closed").click(function () { // do the toggle (change parameter) $(this).next().toggle(); $(this).toggleClass("open"); tellMe($(this),"Before if(.is(:visible'))"); // change the prompt if ($(this).next().is(":visible")){ $(this).html("Less" ); } else { $(this).html("More"); } }); // helper functions function h5nextVisible(when){ // report the status of h5.next visible // do this with .each because there could be more than one $("h5.closed").next() .each(function(){ //console.log($(this)); var msg = when ; msg += " h5.closed.next().is(':visible') " ; msg += $(this).is(":visible") ; console.log(msg); }); } // helper function to write to log function tellMe(elem,when){ var msg=when + " "; msg+="visible is: "; msg+=$(elem).next().is(":visible") + ", "; msg+="class is: " ; msg+= $(elem).attr("class"); console.log(msg); } }); >