Please tell us about your actual intention because there is definitely some better way to do what you want. Why do you need to add a class “hasItems”? Also, you need to check for the length of the list items (children) of the ol, not the ol itself.
And your fiddle seems to work, by the way, you just need to choose the right framework.
Donít click this link!