Hi,
Apparently, it’s the find(“img”) that’s looking for non-existing descendent elements and returning undefined. Changing
var imageid = jQuery(html).find(‘img’).attr(‘class’).match(/wp\-image\-([0-9]+)/)[1];
to
var imageid = jQuery(html).attr(‘class’).match(/wp\-image\-([0-9]+)/)[1];
seems to solve the problem.