8

I want to do something with each hidden input value, so I coded the following javascript using jQuery.

$.each($("input[type='hidden']"), function (index, value) {
    alert(value.val());
});

But I get he following execution error: value.val is not a function.

What am I doing wrong?

2 Answers 2

14

This would work:

$("input[type=hidden]").each(function() {
     $(this).val() //do something with
});
Sign up to request clarification or add additional context in comments.

2 Comments

Just to add, there's also the :hidden pseudo selector, so input:hidden yields the same matches.
Actually I'm not quite sure what karim79 has written here is correct. I believe input:hidden will select input elements which have been made invisible by virtue of CSS (for instance) and that's not the same as finding input elements of type hidden. The original question is a little ambiguous on what was wanted but I'm just mentioning it in case it's useful.
9

The value in the iterating function is a Node, not a jQuery object.

You still need to go: $(value).val();

See the last example here: http://api.jquery.com/each/

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.