{"name":"jQuery.parseHTML","type":"method","title":"jQuery.parseHTML()","deprecated":null,"removed":null,"desc":"Parses a string into an array of DOM nodes.","categories":["utilities","version/1.8"],"entries":[{"return":"Array","signatures":{"added":"1.8","argument":[{"desc":"HTML string to be parsed","name":"data","type":"String"},{"desc":"Document element to serve as the context in which the HTML fragment will be created","name":"context","type":"Element","optional":"true","default":"document"},{"desc":"A Boolean indicating whether to include scripts passed in the HTML string","name":"keepScripts","type":"Boolean","optional":"true","default":"false"}]},"examples":{"desc":"Create an array of Dom nodes using an HTML string and insert it into a div.","html":"\n
jQuery.parseHTML uses a native DOM element creation function to convert the string to a set of DOM elements, which can then be inserted into the document.
By default, the context is the current document if not specified or given as null or undefined. If the HTML was to be used in another document such as an iframe, that frame's document could be used.
Most jQuery APIs that accept HTML strings will run scripts that are included in the HTML. jQuery.parseHTML does not run script in the parsed HTML unless keepScripts is explicitly true. However, it is still possible in most environments to execute script indirectly, for example via the <img onerror> attribute. The caller should be aware of this and guard against it by cleaning or escaping any untrusted inputs from sources such as the URL or cookies. For future compatibility, callers should not depend on the ability to run any script content when keepScripts is unspecified or false.