Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get exact html() with closing tag for which starting tag is missing

Currently for a body with HTML: hello</div><p>hai</p><span>Welcome</span> on alerting $('body').html() it alerts hello<p>hai</p><span>Welcome</span>.

Fiddle

But I want it to display hello</div><p>hai</p><span>Welcome</span> i.e. Alert HTML as it is written within the body.

I can see the exact code when I view the source-code of the page.I really dont know if client-side scripts are capable of displaying the output I asked.

Is it possible ?And if yes How?

like image 380
Zword Avatar asked Mar 13 '14 18:03

Zword


People also ask

How do you find missing closing tags in HTML?

If you save your HTML as page. xhtml (instead of page. html ), the browser (Firefox/Chrome or Opera) should find the un-closed tags for you without the need for a validator. Just remember to rename them .

Which tag is used for closing in HTML?

An opening tag begins a section of page content, and a closing tag ends it. For example, to markup a section of text as a paragraph, you would open the paragraph with an opening paragraph tag <p> and close it with a closing paragraph tag </p> (closing tags always proceed the element with a /).

Which tag contains both starting and closing tag?

The most common example is the <html> tag, which has both a starting tag and ending tag.

Which tag does not have a closing?

What Is a Void Element? The void elements or singleton tags in HTML don't require a closing tag to be valid. These elements are usually ones that either stand alone on the page ​or where the end of their contents is obvious from the context of the page itself.


1 Answers

You could make an ajax request, this way the HTML won't be parsed:

$.get(window.location.href,function(data){console.log(data);});

See DEMO

like image 96
A. Wolff Avatar answered Oct 25 '22 11:10

A. Wolff