beginner beginner - 1 year ago 71
HTML Question

Why .html() don't output html tags?

If i have a p element

<p> simple text <h3> this is h3 text </h3> </p>

And i do this.


It should give output
simple text <h3> this is h3 text</h3>

But it alerts only
simple text
. I thought Ok may be
does not output html tags

But when i add any html using jquery in same p element , And then alert in same way it gives me result which is expected(it shows html tags as well) .

This is example

Can someone explain why this different behaviour ? Thanks in advance

Answer Source

If you go into chrome inspector for the JS fiddle page you linked you'll notice the HTML gets rendered as this:

<p id="firstp">
simple text</p><h3>
this is h3 text

A closing paragraph tag is added just before your starting header tag.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download