SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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');
    });

    });

    });

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,069
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    You were almost there, it should be:

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

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    You were almost there, it should be:

    Code:
    $(document).ready(function(){
    						   
    $('#hideButton').live('click',function() {
    var $this = $(this);									   
    $('#disclaimer')
    	.slideToggle('300', function(){
    			 $this.val($this.val()=='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.

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,069
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by amit.e View Post
    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
    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.

  5. #5
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •