help me to filter html in jquery
I have a string:
var s = "<h1>1</h1><h2>1.1</h2><h3>1.1.1</h3><div><h1>2</h1><h2>2.1</h2><h3>2.1.1</h3></div>"
I want to get all header's html so that the expect output is:
1
1.1
1.1.1
2
2.1
2.1.1
Then I write jquery code:
-
$(s).find(":header").each(function() {
$("body").append("<div>" + $(this).html() + "</div>");
});
But the result shows only headers in <div> are found.
2
2.1
2.1.1
Then I tried filter function:
-
$(s).filter(":header").each(function() {
$("body").append("<div>" + $(this).html() + "</div>");
});
Now the result is:
1
1.1
1.1.1
The headers in <div> are missing.
Please help me. How can I get all headers with original order.
I just want to get a contents from loaded HTML.