Answer the question
In order to leave comments, you need to log in
Why is an object returned?
There is a comment block html
<ul class="messages">
<li class="message-item">
<div class="name">12345</div>
<div class="text" id="7">2 qeqwraweawa</div>
</li>
<li class="message-item">
<div class="name">12345</div>
<div class="text" id="8">3кукуыкцук</div>
</li>
<li class="message-item">
<div class="name">12345</div>
<div class="text" id="9">4кукуыкцук</div>
</li>
<li>
<a href="" onclick="return false;" class="answer" style="display: none;">Ответить</a>
<form action="" method="post" class="form-answer row" style="display: block;">
<div class="col-md-8">
<textarea name="text" placeholder="Текст сообщения..." class="text"></textarea>
<input type="hidden" name="parent_id" id="parent" value="">
</div>
<div class="col-md-12">
<input type="submit" class="submit">
<a href="" onclick="return false;" class="cancel">Отменить</a>
</div>
</form>
</li>
</ul>
$('.answer').click(function () {
if( $(this).parent().parent().find('.message-item').length ) { //проверяем наличие комментариев
var mi_id = $(this).parent().parent().find('.message-item:last').find('.text').val('id'); выбираем id последнего комментария
$(this).parent().find('#parent').val(mi_id); //изменяет параметр value у hidden инпута
}
});
Answer the question
In order to leave comments, you need to log in
In the line after
write
And look what will be displayed.
And even cooler - to master the debugger.
I suspect that you want to pull out text or something like that from some block or inline element. In your case div $('.text') val does not exist. val exists on elements like textarea etc... you need $('.text').text(), secondly read jquery and it's features.... you will someday have a hard task and write a lot of code parent parent parent - use .closest() - this is the closest parent.... So as not to duplicate code....
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question