Small JavaScript helper for setting the `data-state` attribute of an element