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')); });
Comments
Post a Comment