Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select All checkbox by Javascript or console

Tags:

I am having 100 Checkboxes on my web page. For testing purposes I want to tick all those boxes, but manually clicking is time consuming. Is there a possible way to get them ticked?

Perhaps a JavaScript or Chrome Console window, anything?

like image 974
Yahoo Avatar asked Jun 06 '12 04:06

Yahoo


People also ask

How do you select all check boxes?

In order to select all the checkboxes of a page, we need to create a selectAll () function through which we can select all the checkboxes together. In this section, not only we will learn to select all checkboxes, but we will also create another function that will deselect all the checked checkboxes.

How do you check all checkbox in inspect element?

Javascript function to toggle (check/uncheck) all checkbox. Try setAttribute . (function() { var aa = document. getElementsByTagName("input"); for (var i =0; i < aa. length; i++){ aa.


1 Answers

The most direct way would be to grab all your inputs, filter just the checkboxes out, and set the checked property.

var allInputs = document.getElementsByTagName("input"); for (var i = 0, max = allInputs.length; i < max; i++){     if (allInputs[i].type === 'checkbox')         allInputs[i].checked = true; } 

If you happen to be using jQuery—and I'm not saying you should start just to tick all your checkboxes for testing—you could simply do

$("input[type='checkbox']").prop("checked", true); 

or as Fabricio points out:

$(":checkbox").prop("checked", true); 
like image 91
Adam Rackis Avatar answered Oct 14 '22 11:10

Adam Rackis