santa
santa

Reputation: 12512

Select HTML content

I need to locate an element and grab an entire block of HTML.

I tried this:

$(this).find('h1').html();

But only was able to capture the text withing h1 tag... What am I missing?

Upvotes: 0

Views: 64

Answers (2)

Joseph Silber
Joseph Silber

Reputation: 220006

Here's a simple plugin. Use it as follows:

$(this).find('h1').outerHtml();

If you don't want to depend on the plugin, here's a solution with less code, but not as efficient:

var html = $('<div />').html( $(this).find('h1').clone() ).html();

Here's the fiddle: http://jsfiddle.net/nxfTf/

Upvotes: 2

Sashenka
Sashenka

Reputation: 246

You could try this.

$(this).find('h1')[0].outerHTML

I did this fiddle, if you need something a little more visual: http://jsfiddle.net/aPGGS/

Upvotes: 1

Related Questions