Using jQuery, I'm trying to make a quick & dirty way of changing the innerHtml text of a control button (#ctrlBtn) to reflect the state of div's slideToggle() using the html() method. I can't seem to get my head around it. It changes the button text on the 1st click but then that's it... here's the code:
<script type="text/javascript">
$(document).ready(function(){
$("#StatsDetail").slideToggle(); //hide it to start
$("button").click(function(){
$("#StatsDetail").slideToggle(); //show/hide
// the next line is not working even w/standard if/else syntax...
($("#ctrlBtn").html!="Hide") ? $("#ctrlBtn").html("Hide") : "#ctrlBtn").html("View");
}); //end-onClick
}); //end-onLoad
</script>
<span class="right"><button><div id="ctrlBtn">View/Hide Details</div></button></span>
<div id="StatsDetail"> Lorem ipsum yadda yadda blah </div>
ive even tried
if ($("#statsDetail").is(":visible")) {
$("#ctrlBtn").html("Hide");
} else {
$("#ctrlBtn").html("View");
}
I know I must be missing something really stupid. Any help would be appreciated.
Joe Negron ~ NYC