10

I have the following using jQuery:

var x = $('.boxes > input:checked');

From x I am trying to retrieve an array of id values and have been unable to work out how to do this.

Something like:

var y = x[id];
// y becomes an array like ['1', '2', '3'] assuming
// that x had 3 checkboxes with id's of 1, 2, 3 etc.
0

1 Answer 1

19

You can use jQuery.map:

var x = $('.boxes > input:checked');

var y = $.map(x, function (element){
  return element.id;
});

The y variable, will be an array containing the element ids.

Sign up to request clarification or add additional context in comments.

1 Comment

Alternatively: var y = x.map(function() { return this.id;}).get();

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.