0

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

Kenci
  • 4,625
  • 13
  • 62
  • 102

2 Answers2

3

You could use the attribute equals selector

$('[question-id="yourvalue"]').closest('div');
Nicola Peluchetti
  • 74,514
  • 30
  • 136
  • 188
0

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");
Frédéric Hamidi
  • 249,845
  • 40
  • 466
  • 467