Ternary statement with jQuery - am I doing something wrong?

I wish to toggle the text of the button based on whether the discalimer is showing it or not. ‘show’ if hidden, ‘hide’ if shown. Its working halfway the second click is not working. Please help me understand this code better

$(document).ready(function(){

$(‘#hideButton’).live(‘click’,function() {
var $this = $(this);
$(‘#disclaimer’)
.slideToggle(‘300’, function(){
$this.val(‘hide’ ? ‘show’ : ‘hide’);
});

});

});

You were almost there, it should be:


$(document).ready(function(){
						   
$('#hideButton').live('click',function() {
var $this = $(this);									   
$('#disclaimer')
	.slideToggle('300', function(){
			 $this.val([COLOR="Red"]$this.val()==[/COLOR]'hide' ? 'show' : 'hide');						 
		});
	
	});

});

Thanks Scallio,
Great Tip - I am learning with sitepoint’s novice to ninja book. What’s your recommendation - if you have one that is.

I don’t have any book on jQuery.
I was quite proficient at javascript before I started jQuery, so I could “map” everything from jQuery to the javascript I knew. Made learning jQuery a real breaze for me :slight_smile:
I also don’t have a book on javascript. I do have one on AJAX, but I forgot it’s name, and if you’ll be using jQuery for AJAX my book will be obsolete to you anyway.

Hi…

The JQuery in Action books works for me. Really concise and a good compromise between an introduction and something I can quickly look things up in. I bought it when copies kept disappearing from the office (a good sign).

It’s the only JQuery book I have though, so others may have better recommendations.

yours, Marcus