I have some jquery variables that attempt to get values of nearby elements however they don't work. I thought closest() was the right selector.
JQUERY:
$(".answerContainer").on("click", ".editAnswer", function(e){
e.preventDefault();
var answer_id = $(this).closest('.answer_id').attr('value'); //this doenst work
HTML:
<p name='singleAnswer' class='singleAnswer'>$answer[$f]</p>
<input type='hidden' value='$answerid[$f]' class='answer_id' />
<p class='ratingBox'> $answerrating[$f]</p>
<div class='answerBar'>";
<a href='#' class='upVote vote'>Upvote</a> · <a href='#' class='downVote vote'>Downvote</a> ·
<a class='answerTime'> $difference $periods[$j] ago</a>
· <a href='#' style='color: orange;' class='editAnswer'><b>Edit</b></a>
Try this, also use
.val()
instead ofattr('value')