javascript - is there a way to write the actual DOM to a string -


i have html document

<html> <head></head> <body> <form> <input type="text" value="" /> </form> <input type="button" id="doit" value="do it"/>     <!-- jquery --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">         </script>                     <script type="text/javascript">         $(document).ready(function() {             $("#doit").click(function(){             var dom = document.documentelement.innerhtml;             alert(dom);             });         });         </script> </body> </html> 

if edit text field value still original blank value in alert...why? , how see actual dom in string?

you'd need set each attribute explicitly current value: http://jsfiddle.net/gw8eu/.

$("#doit").click(function(){     $('*').each(function() {         var $this = $(this);         for(var = 0; < this.attributes.length; i++) {             try {                 var t = this.attributes[i];                 $this.attr(t.name, $this.prop(t.name));             } catch(e) {}         };     });     var dom = document.documentelement.innerhtml;     alert(dom); }); 

it's rather dirty , not see real rationale behind outputting dom string, seems answer question.

one of reasons it's dirty try block essential, because otherwise you'd setting type attribute of input immutable. i'm pretty won't work other special attributes either, value of input works fine.

therefore still know what's reason behind wanting dom string; there more elegant solution.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -