I'm puzzled about getting a simple toggle to work that should be fairly simple. I want the div to fade out when the opacity is 100 and fade in when it is 0. http://jsfiddle.net/mGdcm/8/
Javascript-
$('#toggleButton').click(function() {
if ($('#toggleSection').css("opacity") === 0) {
$('#toggleSection').fadeIn("slow");
}
else {
$('#toggleSection').fadeOut("slow");
}
return false;
});
HTML-
<a href="#" id="toggleButton">toggle</a>
<div id="toggleSection" style="opacity:0;"> <p>Why isn't this working?</p></div>
.css("opacity")returns a string, so you'd need=== "0"or== 0. And you'd need.fadeTo("slow", 1)since you're not setting thedisplaycss property.