I wanted to remove all text from html and print only tags. I Ended up writing this:
var html = $('html');
var elements = html.find('*');
elements.text('');
alert(html.html());
It only out prints <head></head><body></body>. Was not that suppose to print all tags. I’ve nearly 2000 tags in the html.
That says “find all elements below
html, then empty them”. That includesbodyandhead. When they are emptied, there are no other elements on the page, so they are the only ones that appear inhtml‘s content.If you really wnat to remove all text from the page and leave the elements, you’ll have to do it with DOM methods: