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

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -