Reputation: 1099
I'm trying to select an element in jQuery but can't do it successfully. I tried prev, prevall and closest but no success.
Basically, when clicking a form, I want to update a value above my form (in a page where the forms will appear multiple times).
I tried making it work in jsfiddle there (one click should return the value above it):
This is what I'm trying to do:
$(".addshowscoreinqtip").click(function() {
var button = $(this);
var curscore = button.closest('.rating-recent-text');
var currentscore = curscore.html();
alert(currentscore);
});
Any help appreciated!
Upvotes: 0
Views: 123
Reputation: 144689
closest
selects the closest matching parent element and prev
selects the direct previous sibling element, you can use both of them:
var curscore = button.closest('.tip-content')
.prev('.trending-container')
.find('.rating-recent-text');
Upvotes: 2
Reputation: 10003
You will need to go up to common parent, .columns
in your case. For example:
$(".clickhere").click(function() {
var button = $(this);
var curscore = button.closest('.columns').find('.rating-recent-text');
var currentscore = curscore.html();
alert(currentscore);
});
Upvotes: 0