Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   проставить значения value (https://javascript.ru/forum/jquery/69402-prostavit-znacheniya-value.html)

miraghyk 20.06.2017 09:40

проставить значения value
 
Есть такой код.


<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

спасибо))


Часовой пояс GMT +3, время: 18:57.