Steve
Steve

Reputation: 4898

How to view HTML Source?

I'm trying here - http://jsfiddle.net/stevea/CRVpL/2/ - to view the source for a div.
The first line below picks up the html ok but the next line doesn't put it where I want.

 var inhtml = $('#box1').html();
 $(inhtml).appendTo('#displaysource');

Could someone point out the correct way to do this? Thanks

Upvotes: 0

Views: 89

Answers (3)

Ngalam City
Ngalam City

Reputation: 112

var inhtml = $('#box1').html();
 $(inhtml).appendTo('#displaysource');

TO

var inhtml = $('#box1');
$(inhtml).appendTo('#displaysource');

if you want to move the contents make this:

 var inhtml = $('#box1').text();
 $('#displaysource').text(inhtml);

Hope you can help

Upvotes: 0

Michael Lorton
Michael Lorton

Reputation: 44376

var inhtml = $('#box1').html();
 $('#displaysource').text(inhtml);

Upvotes: 1

PSL
PSL

Reputation: 123739

Use .text()

 $('#displaysource').text(inhtml);

Demo

When you do $(inhtml).appendTo(.. the html will append to the div as elements, but if you want to see it as text they needs to be escaped and thats what .text() does on html tags.

Upvotes: 4

Related Questions