How to write ternary operator condition in jQuery?

后端 未结 9 1466
眼角桃花
眼角桃花 2020-12-29 19:41

In this fiddle http://jsfiddle.net/mjmitche/6nar4/3/, if you drag, for example, the little blue box into the yellow box, then the big black box will turn pink. All of the 4

9条回答
  •  隐瞒了意图╮
    2020-12-29 19:47

    Also, the ternary operator expects expressions, not statements. Do not use semicolons, only at the end of the ternary op.

    $("#blackbox").css({'background': 
        $("#blackbox").css('background') === 'pink' ? 'black' : 'pink'});
    

提交回复
热议问题