I have this JavaScript / jQuery snippet where I have a hidden textarea
and a href
. The intention is to click on href
to textarea
to appear so that the person can type his answer.
I'm not able to open textarea
in href
matching.
By clicking on a href
, it opens for all questions.
<script>
$(document).ready(function() {
$.ajax({
type:'post',
dataType:'json',
url: 'listAllForum',
success: function(dados){
for(var i = 0; dados.length > i; i++){
$('#post-forum').append('<div>' + dados[i].idForum + ' - ' + dados[i].message + '</div>' +
'<div class="respostas" data-respostaId=' + dados[i].idForum + '>' +
'<textarea rows=6 cols=95 class="res" value="" name="dados" style="display:none;"/> <br>' +
'<a href="#" id="resp" class="resposta">Responder</a>' +
'</div> <br> <br>');
}
}
});
$(document).on('click', '.respostas', function (event) {
var idPergunta = $(this).attr('data-respostaId');
$('.res').show();
$.ajax({
type:'post',
dataType:'json',
url:'saveAnswer',
success: function(resposta){
}
});
event.preventDefault();
});
});