Get raw HTML from div using js?

I am working on a site where users can create and save their own HTML forms. Instead of inserting form elements and identifiers one by one into the database, I thought of using js (preferably jquery) to simply get the HTML form (in the source code format) and paste it into the text string via mysql.

For example, I have a form in a div

<div class="new_form">
<form>
Your Name:
<input type="text" name="something" />
About You:
<textarea name=about_you></textarea>
</form>
</div>

With js, is it possible to get raw HTML in the div "new_form"?

+3
source share
3 answers

To get all the HTML inside the div

$(".new_form").html()

To get only text, it will

$(".new_form").text()

, HTML, ( #, )

+11

, innerHTML html(), , HTML-, . - , HTML.

, , , , , , & - . IE, , HTML, , , . IE value.

, HTML-. , HTML .

+4

Yes it is. You are using the innerHTML property for the div. Like this:

var myHTML = document.getElementById('new_form').innerHTML;
+3
source

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


All Articles