I have a variable scrollbar that contains >=0 data elements added with addItemBefore. When scrollbar contains zero elements, a specific event needs to trigger. I have all the working code for scrollbar and the event, although I don’t know how to check if scrollbar contains no data elements.
Relevant code:
var scrollbar = $("#scrollbar-id").data("scrollable");
…
function addElement(message) {
…
scrollbar.addItemBefore(message); }
I’d like to retrieve the number of items in scrollbar inside another function to trigger the event.
Call
scrollbar.getItems()and then check thelength