var but1 = $("#button"); var red = $("#box"); but1.click(function() { red.fadeToggle("slow"); var text = $(this).text(); if (text == "hide") { $(this).text("show"); } else { $(this).text("hide"); } });
<div id="button">hide</div> <div id="box"></div>
#box { width:300px; height:300px; background-color:red; margin: 0 0 0 80px; } #button { width:40px; height:40px; background-color:green; float:left; } #button2 { width:30px; height:30px; background-color:yellow; float:left; }