Logging HTML and the forms using Jquery

I need to log the html, to do this you can just add $.('html') but in here if there is form on the html it wouldn't save the input...
So found a code that combines them together i think this works just fine for logging a website using jquery :)


$(".loghtml").click(function(){
$('form input').each(function() {
this.setAttribute('value', this.value);
});

$('form select').each(function() {
var index = this.selectedIndex;
var i = 0;
$(this).children('option').each(function() {
if (i++ != index) this.removeAttribute('selected');
else this.setAttribute('selected', 'selected');
});
});

$('form textarea').each(function() {
$(this).html($(this).val());
});
var src = $('HTML');
console.log(src);
});