0

This is a link for an example of Edit source Code:

http://neokoenig.github.io/jQuery-gridmanager/demo/tinymce.html

the button which value is </>.

He get the code HTML even if he changes the content of the grid.

How to get the source code HTML using JavaScript or jQuery?

Thanks.

5 Answers 5

2

Using JavaScript

document.documentElement.outerHTML

More info

or

document.documentElement.innerHTML

More info

Sign up to request clarification or add additional context in comments.

Comments

2

you can use the html method with jquery, i.e for get the whole page html like this:

$( document ).ready(function() {
    console.log($("html").html());
})

8 Comments

this html() get code html after is genereted I need to get code html as I typed in my IDE
i'm trying to understand what you want to do. but i can't lol... please tell us what you want to do
I'm working with angular2 and there is some input wich I add in html code like this <input [name] type="text" /> and when I get my code using method html() I dont get [name] as I typed in my IDE(intellij)
but do you see the input rendered in the document??? if yes use 'html();' into a document ready function
can you give an example for using html() into a document ready function
|
1

I'm not sure what you want to do exactly but if you want to get raw source code from jQuery you can use the following:

var html = $('element').html();

And with pure javascript from an id

var html = document.getElementById('id').innerHTML;

or from classname

var html = document.getElementsByClassName('class').innerHTML;

And to get the content of your example (which is an editor called tinymce) you can use the command tinymce.activeEditor.getContent(); or tinyMCE.get('myTextarea').getContent()


EDIT: If you want to listen for changes with jQuery and display to html dynamically you'd want to do something like this:

$('yourTextArea').keyup(function() {
    var html = $(this).val();
    $('yourElementToDisplayTheHTML').html(html);
});

3 Comments

this html() get code html after is genereted I need to get code html as I typed in my IDE
Do you mean like an event listener while typing that displays your html instantly? Are you using tinymce or just an textarea/input?
yess some things like that when I add some code dynamically in my page html I want it be dsplayed (I'm not using tinymce)
0

I've built a simple API, just use this:

<script src="https://cdn.jsdelivr.net/gh/Parking-Master/viewsource@latest/vs.js"></script>

In your JavaScript:

getSource('https://example.com/');

Comments

-2

in http response header, you can find "content-type" header. that header indicates how contents of page should be rendered. so, if you want to render page as plain text("source code", as you mentioned), just change that header like this -> "content-type : text/plain; charset=UTF-8"

if you can use ajax in jquery or javascript

use like this

$("button").click(function(){
$.ajax({url: "page_you_want.html", success: function(result){
    alert(result);
}});

});

1 Comment

This has nothing to do with requests and therefore no headers. OP need to get raw html contents from his editor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.