You will want to use a combination of the closest
and attr
methods in jQuery.
For example:
var userId = $(this).closest(.answercontainer).attr('id');
$(this)
is a jquery object for the element that was clicked on
.closest(selector)
traverses up the DOM tree until it reaches a match for the selector
.attr('id')
gives you the value in the id attribute of the traversed to element
If the ID is elsewhere in your DOM you may need to look at some other traversing methods such as siblings
or find
.