jQuery each to iterate through inputs and store values in array -
i have multiple hidden inputs name image_values:
<input class="imagevalues<?=$category->cat_id;?>" name="image_values[]" type="hidden" value="<?=$step->img_pos.":".$option->image_path;?>" />
i want iterate through each of them , store values in array, trying below, isnt going inside each @ all, doing wrong?:
var imagevalues = ''; jquery("input[name='image_values']").each(function(){ imagevalues = jquery(this).val(); });
thanks
- you can use
map()
that. return jquery collection of returned in function..get()
converts normal array. - you need include square brackets in selector, , escape them:
var imagevalues = jquery("input[name='image_values\\[\\]']").map(function(){ return this.value }).get()
Comments
Post a Comment