Вход

Просмотр полной версии : проставить значения value


miraghyk
20.06.2017, 09:40
Есть такой код.


<div class="row_item">
<h1>first item</h1>
<img src="img/12803143.jpg" alt="">
<span></span>
<input placeholder="text here " type="text">
</div>
<div class="row_item">
<h1>second item</h1>
<img src="img/12803143.jpg" alt="">
<span></span>
<input placeholder="text here " type="text">
</div>
<div class="row_item">
<h1>third item</h1>
<img src="img/12803143.jpg" alt="">
<span></span>
<input placeholder="text here " type="text">
</div>

Как каждому inputu проставить value, равное h1 из того же блока row_item?

если так
$('.row_item input').each(function(){
$(this).attr('value', $('h1').html());
});

то один h1 ставит всем inputам

laimas
20.06.2017, 11:23
this.value = $(this).prevAll('h1').text();

miraghyk
20.06.2017, 12:08
спасибо))