I want to insert all label values in my p class rowSvar
. I tried this script undereath but I get both answers in my p tag. How do I only get each answer?
<div class = "rows">
<div class = "row" id = "rowOne">
<p>Förväntas deltagarna arbeta kreativt?</p>
<p class = "rowSvar"></p>
<p></p>
<p></p>
</div>
<div class = "row" id = "rowTwo">
<p>Vad är huvudmålet med mötet?</p>
<p class = "rowSvar"></p>
<p></p>
<p></p>
</div>
var labels = $('#from :checked').map(function() {
return $(this).closest('label').text();
}).get();
labels.forEach(function(e) {
$('.rowSvar').append(e);
});
CodePudding user response:
You should specify which .rowSvar
should receive which answer.
$('.rowSvar')
selects multiple elements, each element should get the appropriate answer, I'm assuming your labels
are ordered exactly as your .rowSvar
s are.
labels.forEach(function(e, index) {
$('.rowSvar')[index].append(e);
});