It appears that $(htmlstring) strips any script tags from the HTML. That is a shame.
The solution I came up with is based on the regex in the answer to How to get regex to match multiple script tags?
var re = /<script\b[^>]*>([\s\S]*?)<\/script>/gm;
var scripts = "";
var match;
while (match = re.exec(data)) {
if (match[1] != "") {
scripts += match[0];
}
}
panel.append(scripts);
I concatenate any inline scripts and the script executes immediately upon being appended to the DOM.