I've got the following scenario:
var el = 'li';
and there are 5 <li>
's on the page each with a data-slide=number
attribute (number being 1,2,3,4,5 respectively).
I now need to find the currently active slide number which is mapped to var current = $('ul').data(current);
and is updated on each slide change.
So far my tries have been unsuccessful, trying to construct the selector that would match the current slide:
$('ul').find(el+[data-slide=+current+]);
does not match/return anything…
The reason I can't hardcode the li
part is that this is a user accessible variable that can be changed to a different element if required, so it may not always be an li
.
Any ideas on what I'm missing?
in case you don't want to type all that, here's a shorter way to query by data attribute:
FYI: http://james.padolsey.com/javascript/a-better-data-selector-for-jquery/
Going back to his original question, about how to make this work without knowing the element type in advance, the following does this:
This selector
$("ul [data-slide='" + current +"']");
will work for following structure:While this
$("ul[data-slide='" + current +"']");
will work for:<ul data-slide="item"><li></li></ul>