").html() in the viewport, I will get an empty string. I assume $("

") no...">

JQuery: html () returns an empty string

If I use firebug and type $("<p>").html() in the viewport, I will get an empty string. I assume $("<p>") not provided to the document. How can I get markup for $("<p>") before adding it to the DOM?

+4
source share
2 answers

You are requesting external HTML, not internal, the HTML inside the <p> really empty.

To get the HTML code, you would have to wrap it in another element, for example:

 jQuery("<div>").append($("<p>").clone()).html() 

This will give you:

 <p></p> 
+5
source

Try $( 'p' ).html() , not $( '<p>' ).html()

Example http://jsfiddle.net/tdg7U/

Warnings Test1 $( '<p>' ).html()

Warnings Test2 $( 'p' ).html()

+2
source

All Articles