1
Hello, I’m a beginner in jquery, and I was looking at the documentation for Jquery Ui, Draggable and Droppable. I’m studying the demo of the site, but I don’t understand this part:
var $list = $( "ul", $trash ).length ?
$( "ul", $trash ) :
$( "<ul class='gallery ui-helper-reset'/>" ).appendTo( $trash );
I don’t understand the part ?
after the .length
and the :
after the $( "ul", $trash )
.
This is the complete function:
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" });
});
});
}
And this is the event that calls the function:
var $gallery = $( "#gallery" ),
$trash = $( "#trash" );
$trash.droppable({
accept: "#gallery > li",
classes: {
"ui-droppable-active": "ui-state-highlight"
},
drop: function( event, ui ) {
deleteImage( ui.draggable );
}
});
It is called "ternary operator". You can find more material here on the website. For example: https://answall.com/q/17398/64969
– Jefferson Quesado
It’s a good question, but we already got her answer on the website.
– mutlei
I suggest leaving the question I mentioned as duplicate, since it addresses the subject directly in JS. For new users, I believe this will facilitate. If someone closes and adds all as related, better.
– Woss
@Andersoncarloswoss I totally agree.
– Victor Stafusa