How can I combine a jQuery variable with a pseudo class - for example:
listItem = $('li');
listItem.addClass(); // Works on all li's
$(listItem).addClass(); // Works on all li's
$('li:first-child').addClass(); // Works ( on first li )
$(listItem + ':first-child').addClass(); // Doesn't Work..
Similarly I'd like to be able to do this with data attributes, for example to use some variant of:
listItem[data-index="1"]
instead of:
$('li[data-index="1"]')
I've found a couple questions which deal with variables after such as $('#element-' + variable'), which don't help in this case.
jQuery: using a variable as a selector,
jQuery selectors with variables
And also tried 'template literals' ( ${id} ) to no avail.