is it possible to get data that contain html element from content editable div.
<div id="content" class="content" name="content" contenteditable="true" spellcheck="false">
<b>hallo</b>world
is it possible to get data that contain html element from content editable div.
<div id="content" class="content" name="content" contenteditable="true" spellcheck="false">
<b>hallo</b>world
2
Answers
You can use the example below, Press Button Save, It will alert the data stored in div.
After this you can use the variable htmlContent that contains the data inside the div.
In order to
insert
the text/html content from acontendeditable
element within a webpage you will need to use Javascript to either send via ajax ( as suggested earlier ) or send as a regular form submission to the server.In the following code example the actual content is sent using
fetch
to the server – in this case it simply useslocation.href
to point to itself but in practice this could be a normal script path, such as/path/to/script.php
On the server, the PHP script will have access to the
POST
array and specificallycontent
via$_POST['content']
– from which point you can craft the sql statement and commit to db.eg:
Note: due to the sandbox restrictions here the snippet will not allow the Fetch request to localhost!