I am creating CKeditor function. Now my problem is I cannot get the value in the CKeditor textarea. I try to console log to show the result, it cannot cannot follow html to show like below the picture:
Below is my coding:
<textarea id="editor1" name="editor1">This is sample text</textarea>
<script type="text/javascript">
CKEDITOR.replace( 'editor1', {
height: 300,
// enterMode: CKEDITOR.ENTER_BR,
filebrowserUploadUrl: "/eokclaim/app/ajaxfile.php?type=file",
filebrowserImageUploadUrl: "/eokclaim/app/ajaxfile.php?type=image"
} );
function updateDiv(){
var editorText = CKEDITOR.instances.editor1.getData();
console.log(editorText);
}
</script>
I want the expected result in console log are (I want the console log result show in 1 line) :
<p>Picture 1:</p><br /><p><img alt="" src="https://www.abc.com.my/folder/app/uploads/blue-pin.png" style="height:100px; width:100px" /></p><br /><p>Picture 2:</p><br /><p><img alt="" src="https://www.abc.com.my/folder/app/uploads/1.png" style="height:34px; width:100px" /></p>
Hope someone can guide me on how to solve the problem. Thanks.
In order to remove line breaks, you can use replace function. Your code would look like :
function updateDiv(){
var editorText = CKEDITOR.instances.editor1.getData().replace(/(\r\n|\n|\r)/gm, "");
console.log(editorText);
}
If getData() is returning a string as I think, it should work.