I have a jquery variable that isnt working and it’s most likeley because i don’t know how to select elements properly. I thought the below selectors would work, but they don’t
JQUERY:
$('.upVote').click(function(e){
e.preventDefault();
var ratebox = $(this).find('.ratingBox'); //this variable isnt working
var answer_id = $(this).children('.record_id').attr('value'); //this one too
HTML:
<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>
</div>
<input type='hidden' name='record_id' value='$answerid[$f]' class='record_id' />
Both
find()andchildren()will look for elements lower in the DOM tree than the current – the elements you’re looking for are both higher. Try this:Fiddle to prove it works