1
$('.data').has(':checkbox:checked').find('.name, .street1, .street2, .county, .city, .postal, .country');

Returns 7 elements inside object in format of [name, street, street2, county, city, postal, country]

But in case if I have more than 1 set of these 7 elements on my page, it will return 14, 21, 28 and so on inside still one single object in a row without any separators.

Is there any way I can iterate through every 7 elements? Tell selector to return me object inside object with 7 elements? ie [[name, street, street2, county, city, postal, country], [name, street, street2, county, city, postal, country]] and so on?

0

2 Answers 2

2

Make multiple data class elements

html

<div class="data">1-7</div>
<div class="data">1-7</div>
<div class="data">1-7</div>

js

var dataArrays = [];
$('.data').has(':checkbox:checked').each(function(){
 dataArrays.push($(this).find('.name, .street1, .street2, .county, .city, .postal, .country'));
});
Sign up to request clarification or add additional context in comments.

Comments

1

Using the each method on .data, you could iterate through the items:

$('.data').has(':checkbox:checked').each(function() {
    var vals = $(this).find('.name, .street1, .street2, .county, .city, .postal, .country');
    some_function(vals);
});

You may have to restructure the way the result is used, but this is the more standard jQuery format.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.