How to write ternary operator condition in jQuery?

后端 未结 9 1543
眼角桃花
眼角桃花 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 20:06

    I'd do (added caching):

    var bbx = $("#blackbox");
     bbx.css('background-color') === 'rgb(255, 192, 203)' ? bbx.css('background','black') : bbx.css('background','pink')
    

    wroking fiddle (new AGAIN): http://jsfiddle.net/6nar4/37/

    I had to change the first operator as css() returns the rgb value of the color

提交回复
热议问题