How do I get the values of classes in jQuery?

console.log($('.package_ids').val());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="hidden" class="package_ids[]" name="package_ids[]" value="6" />
<input type="hidden" class="package_ids[]" name="package_ids[]" value="775" />
<input type="hidden" class="package_ids[]" name="package_ids[]" value="7207" />

I’m getting the right results when submitting this as a form. But when I get the value using jQuery I’m getting undefined.

I’m hoping to get something like an array [6, 775, 7207].

21 thoughts on “How do I get the values of classes in jQuery?”

Leave a Comment