Get display 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) in the input field, click the button and see the โ€œvisualizedโ€ html-code of the page in the warning pop-up window.

What I see:

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

What I want to see:

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

Is it possible to use JS or jQuery?

+5
source share
2 answers

Here is what I added to your JS

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

I mainly use the jQuery attr () function. The first parameter refers to the attribute you want to manipulate, and the second attribute is the value to provide.

Here is a working demo

+6
source

Here is your solution:

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <script> $(document).ready(function(){ $("#btn").click(function(){ var value = $("#test").val() alert(value); }); }) </script> <input id="test" value=""> <input type="button" id="btn" value="Get"> 
0
source

Source: https://habr.com/ru/post/1245129/


All Articles