Here is the thing,
I have a textarea (with ID “input_container”) full of HTML code, the simple example is:
<!doctype html>
<html>
<head></head>
<body>
<a href="www.example.com">the other place</a>
</body>
</html>
I parsed it using jQuery, here is my code:
I have all this HTML string into variable named domString like this:
domString = $('#input_container').val();
To get a parse HTML of everything inside variable domString, I had to wrap it with another tag, so I did:
dom = "<allhtml>" + domString + "</allhtml>";
And got everything inside a jQuery selector to be parsed:
dDom = $(dom);
After that I checked what’s in dDom, so I did
alert(dDom.html());
That should give me anything inside the tags, right?
But unfortunately, all I get is:
<a href="www.example.com">the other place</a>
And all the other tags are mysteriously gone. Can anyone explain this phenomenon and tell me how to really parse all the DOM?
Thank you
From the jQuery documentation:
This should work instead:
This is kind of a weird thing to do, though- you might want to think about other ways to do what you’re trying to accomplish, I worry that you might be suffering from the XY Problem.