I have an Html string like this:
<div id="foo">
<h1 class="greeting">Hello World!</h1>
</div>
I need to convert this html string to Object in Javascript. i.e., I should get the same object result when used .children()
method in jquery.I tried something like this:
a = '<div id="foo">
<h1 class="greeting">Hello World!</h1>
</div>';
eval("{"+a+"}");
console.log(a);
But it didn't work. What method should I use in javascript to convert HTML string to Object notation. I should get each children node in object form. I do not want to use Jquery in this solution. I am expecting the exact output as shown in console