Question:
The HTML content of the template is converted to jQuery times’s following error:
Syntax error, unrecognized expression:
Syntax error, unrecognized expression:
Operation code:
var linkUl = $(“#linkUl”), listHeight;$(this.linkTemplate).appendTo(linkUl);
The modified operation code:
var linkUl = $(“#linkUl”), listHeight;$($.parseHTML(this.linkTemplate, document, true)).appendTo(linkUl);
Reason: jQuery 1.9 * starts with parseHTML, the HTML content in script, which must be converted to use for security. Otherwise, it will not be able to resolve the error of HTML content.
Usage:
$($.parseHTML(this.linkTemplate))
Solution code:
// This can come from an evil person
var html = “<p>hello</p><script src=’bad.js’></script>”
// Won’t load/run the script in 1.10
$(html).appendTo(“body”);
// Loads and runs
script$($.parseHTML(html, document, true)).appendTo(“body”);