jquery - Javascript is losing variable content -
i have lots of pages structured this:
<body> <table><tr><td align="center" width="100%"> --page html-- </td></tr></table> </body>
and have change page following structure short period of time:
<body> <div style="width: 100%; min-height: 960px; text-align: center;"> --page html-- </div> </body>
so decided use jquery.
here code.
$(document).ready(function(){ var pagehtml = $("td:first").html(); $("table:first").remove(); console.log(pagehtml); $("body").html('<div style="width: 100%; min-height: 960px; text-align: center;">'+pagehtml+'</div>'); });
the problem instead of having expected result have
<body> <div style="width: 100%; min-height: 960px; text-align: center;"></div> </body>
(i don't have page html in div element)
now diagnostic purposes added line console.log(pagehtml);
, return correct html string.
i'm out of ideas make work, suggestions?
thanks help.
try following:
var $div = $("<div />").css({ 'width': '100%', 'min-height': '960px', 'text-align': 'center', 'color': 'red' }); $div.appendto('body'); $div.html($("td:first").html()); $("td:first").remove();
Comments
Post a Comment