SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Jquery function

Hybrid View

  1. #1
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Jquery function

    Hi there,
    could someone please explain the following function to me:

    Code:
    	// image deletion function
    		var recycle_icon = "<a href='link/to/recycle/script/when/we/have/js/off' title='Recycle this image' class='ui-icon ui-icon-refresh'>Recycle image</a>";
    		function deleteImage( $item ) {
    			$item.fadeOut(function() {
    				var $list = $( "ul", $trash ).length ?
    					$( "ul", $trash ) :
    					$( "<ul class='gallery ui-helper-reset'/>" ).appendTo( $trash );
    
    
    				$item.find( "a.ui-icon-trash" ).remove();
    				$item.append( recycle_icon ).appendTo( $list ).fadeIn(function() {
    					$item
    						.animate({ width: "48px" })
    						.find( "img" )
    							.animate({ height: "36px" });
    						 	
    				});
    				
    			});
    		}
    In particular, I do not follow:

    var $list = $( "ul", $trash ).length ?
    $( "ul", $trash ) :
    $( "<ul class='gallery ui-helper-reset'/>" ).appendTo( $trash );
    thanks
    "Persistence is the path to perfection"

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    ? is the ternary operator, which acts like a compact if-else statement. That code is equivalent to:

    Code:
    if ($( "ul", $trash).length) {
        var $list = $( "ul", $trash );
    } else {
        var $list = $( "<ul class='gallery ui-helper-reset'/>" ).appendTo( $trash );;
    }

  3. #3
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thankyou very much
    "Persistence is the path to perfection"


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
  •