I'm trying to count how many elements (list) have the html data attribute of 'data-facet', but I'm undefined.
Here is what I have tried:
$('li').data('facet').length;
Any ideas where I've gone wrong?
If data('facet') represents an integer, then that would explain the undefined result (because you can't run .length on an integer). You can fix this by doing $('li').data('facet').toString().length; instead, but that's not going to get you the result you want (instead, it will give you the length of the data-facet value of the first li element).
To get the desired count of lis, do this:
$('li[data-facet]').length
That will give you the number of li element that have the data-facet attribute.