jQuery how to find an element based on a data-attribute value? -
i've got following scenario:
var el = 'li';
and there 5 <li>
's on page each data-slide=number
attribute (number being 1,2,3,4,5 respectively).
i need find active slide number mapped var current = $('ul').data(current);
, updated on each slide change.
so far tries have been unsuccessful, trying construct selector match current slide:
$('ul').find(el+[data-slide=+current+]);
does not match/return anything…
the reason can't hardcode li
part user accessible variable can changed different element if required, may not li
.
any ideas on i'm missing?
you have inject value of current
attribute equals selector:
$("ul").find("[data-slide='" + current + "']");
es6 way:
$("ul").find(`[data-slide='${current}']`)
Comments
Post a Comment