jquery - Add value of div attribute into INPUT -


struggling adding values of divs' attributes inputs:

my html is:

  <div class="modal-body" client-name="test1">       <input class="gform_hidden"/>   </div>   <div class="modal-body" client-name="new name">       <input class="gform_hidden"/>   </div>   <div class="modal-body" client-name="test3">       <input class="gform_hidden"/>   </div> 

and jquery code:

  $('.modal-body').each(function () {      var cname = $(this).attr('client-name');      $('input.gform_hidden').val(cname);  }); 

can 1 me individual value not last one.

please see jsfiddle below: http://jsfiddle.net/9nph7eyc/

you need use current context this along find selector find input element in it:

 $('.modal-body').each(function () {      $(this).find('input').val($(this).attr('client-name'));  }); 

working demo


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -