Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Poll for changes to element selects in Craft CMS
$(function () {
// Bind a greedy event handler
$('body').on('elementselectchange', '.elementselect', onElementSelectChange);
// Poll to evalute elementselects every 10ms
setInterval(evaluateElementSelects, 10);
function evaluateElementSelects ()
var elementSelect,
$('.elementselect').each(function () {
elementSelect = $(this).data('elementSelect');
elementIds = $.map(elementSelect.$elementsContainer.children(), function (element) {
return $(element).data('id');
if (elementIds !== elementSelect.$'elementIds')) {
.data('elementIds', elementIds)
function onElementSelectChange (e)
var $elementSelect = $(e.currentTarget);
console.log('element select changed in some way', $elementSelect, $'elementIds'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment