javascriptjqueryarrayscheckboxchrome-app-developer-tool

How to select a N number of checkboxes using console?


I'm trying to select a N number of checkboxes of a list by console, but I don't know exactly how to do it. I have this list of data, and I have to delete all registers, but the system doesn't allows me to delete more than 200 items, and my "check all" button checks more than 200 items. So I decided to check the checkboxes using the Console. Can someone help me? Each checkbox has a name: "msgid1", "msgid2", "msgid3"...

my progress so far:

for(i = 1, i < 10, i++){
  var myList = document.getElementsByName("msgid"+i); 
  myList[0].prop("checked", true);
}

P.S.: I don't have permission to edit the code. Thank you.


Solution

  • the selector input[name*='msgid will grab all inputs that start with "msgid"

    and if you wanted to check all of them then set var number = list.length

    https://jsfiddle.net/n0sytxd9/

    var list = $("input[name*='msgid']");
    var number = 5;
    
    if(number<list.length)
    for(var i=0;i<number;i++){
        $(list[i]).attr('checked',true);   
    }