How to write ternary operator condition in jQuery?

后端 未结 9 1539
眼角桃花
眼角桃花 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:00

    From what it looks like you are trying to do, toggle might better solve your problem.

    EDIT: Sorry, toggle is just visibility, I don't think it will help your bg color toggling.

    But here you go:

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

提交回复
热议问题