How do a find an element which has the attribute "question-id" and equals a specific value? From there, i need to find the closest div (the wrapper of this element).
Thanks
How do a find an element which has the attribute "question-id" and equals a specific value? From there, i need to find the closest div (the wrapper of this element).
Thanks
You could use the attribute equals selector
$('[question-id="yourvalue"]').closest('div');
Use an Attribute Equals selector and the closest() method:
var wrapper = $("[question-id='yourValue']").closest("div");
As an aside, note that you can use an HTML5 data attribute (e.g. data-question-id
) to embed information in your element without putting the validity of your markup in jeopardy. In that case, the code above would become:
var wrapper = $("[data-question-id='yourValue']").closest("div");