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
.innerHTMLmechanism. In most cases, jQuery creates a newelement and sets theinnerHTMLproperty 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
.innerHTMLproperty to parse the passed HTML and insert it into the current document. During this process, some browsers filter out certain elements such as,, orelements. As a result, the elements inserted may not be representative of the original string passed.