jQuery get DOM element as string jQuery get DOM element as string jquery jquery

jQuery get DOM element as string


How about

$(selector).prop("outerHTML");


An old trick:

var selector = ":input[type=text]:first";var str = $(selector).clone().wrap('<div/>').parent().html();

Update You don't need to worry about calling .parent() since you're working with an orphaned clone of the original selector.


Use jQuery.html() by appending to a created element.

$('<div/>').append($(":input[type=text]:first").clone()).html()

Here is a fiddle providing an example: http://jsfiddle.net/Zwbmx/1/