Toggle Checkbox using JavaScript

后端 未结 5 2237
栀梦
栀梦 2021-02-06 06:07

I had this working, but I didnt save and cannot replicate. I am trying to toggle checkboxes using if else. What am I doing wrong.

What I thought would work

5条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 06:51

    I thought I would add to this since it led me to an answer I was seeking for checking all checkboxes with bookmarklet. Using the bitwise operator worked like a charm in IE 11 and Chrome. Haven't tried it in other browsers.

    javascript:(function(){var chbxs=document.querySelectorAll('input');for(i in chbxs){chbxs[i].checked^=1;}})();
    

提交回复
热议问题