Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get rendered page using JS or JQuery

Here is my HTML code:

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.7.2.js"></script>
</head>
<body>
  <input id="test" value="">
  <input type="button" id="btn" value="Get">
</body>
</html>

And JS:

$('#btn').click(function(){
  alert(document.documentElement.innerHTML);
});

http://jsbin.com/wuveresele/edit?html,js,output

I want to enter some value (for example, 123) into input field, click button and see "rendered" html code of the page in an alert popup.

What I see:

...
<input id="test" value="">
...

What I want to see:

...
<input id="test" value="123">
...

Is it possible using JS or JQuery?

like image 574
Vitaly Avatar asked Mar 16 '16 04:03

Vitaly


1 Answers

Here's what I added to your JS

$('#btn').click(function(){
  $("#test").attr("value",$("#test").val());
  alert(document.documentElement.innerHTML);
});

What I'm essentially doing is using the Jquery attr() function.The first parameter refers to the attribute you want to manipulate and the second attribute is the value to be given.

Here is the working demo

like image 52
Satej S Avatar answered Nov 20 '22 03:11

Satej S