0

When using .data('keyname') on a jQuery set, I only seem to get the first value. I would like it to return an array of values from each element.

Is there a jQuery shortcut for pulling all values that does not involve iterating the set yourself?

1 Answer 1

4

Use .map:

var dataValues = $(".yourElementSelector").map(function() {
    return $(this).data("keyname");
}).get();

This is about as short as it gets... dataValues will now be a nice array of your data('keyname') values.

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

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.