Help, I puzzle over which day it is necessary for this, in general, there is html:
<div class='some1'> <input type='checkbox'> <input type='checkbox'> <input type='checkbox'> <input type='checkbox'> </div> <div class='some2'> <input type='checkbox'> <input type='checkbox'> <input type='checkbox'> <input type='checkbox'> <input type='checkbox'> </div> <div class='some3'> <input type='checkbox'> <input type='checkbox'> <input type='checkbox'> <input type='checkbox'> <input type='checkbox'> <input type='checkbox'> </div> It is necessary to find out the values of all checkboxes in this html and put them into an array, it should look something like this array['onononon','offonononon',....]
The problem is that you need to understand whether the checkbox is in a certain <div> and put it into an array, respectively. The output should be an array of strings of box values in accordance with the <div> . I tried this:
var numq = 3; // переменная в которой хранится количество divov на странице(она считает создаваемые дивы) var templatevar; //Временная переменная , для хранения строки var answers = [];//Переменная для ответов var workingclass = 'some1';//Начальный класс div for(var i = 0; i<numq; i++){ $('.some'+i+' input[type=checkbox]').each(function(){ if($(this).parent().prop('class')==workingclass){ templatevar += $(this).val(); // returns in var 'on' or 'off' as default } else{ answers.push(templatevar); templatevar = $(this).val(); workingclass = $(this).parent().prop('class'); } }); } console.log(answers); But in the end, this code does not work. Tell me something.