I got an html page through an AJAX request
$.ajax({
async: true,
method: \'GET\',
url: linkPage,
// cache: true,
success: function (data) {
The reason it doesn't work the way you tried is explained in the jQuery documentation:
If the HTML is more complex than a single tag without attributes, as it is in the above example, the actual creation of the elements is handled by the browser's
.innerHTML
mechanism. In most cases, jQuery creates a new
element and sets theinnerHTML
property of the element to the HTML snippet that was passed in.Since you can't have a
inside a
, the browser ignores thetag.
The documentation goes on to say:
When passing in complex HTML, some browsers may not generate a DOM that exactly replicates the HTML source provided. As mentioned, jQuery uses the browser's
.innerHTML
property to parse the passed HTML and insert it into the current document. During this process, some browsers filter out certain elements such as,
, or
elements. As a result, the elements inserted may not be representative of the original string passed.