HTML editor.value() and editor.body.innerHTML return different values

1 Answer 8 Views
Editor
Sebahattin
Top achievements
Rank 1
Iron
Sebahattin asked on 06 May 2024, 06:48 AM
Hello,

When focused in the HTML editor, I set the default font and font size and add a p tag to the outermost.
Then when I try to get the editor value with editor.value() it automatically gets a space ' ' is being added, but when I read it with editor.body.innerHTML there is no space.
This does not allow you to check whether the space was added by the user.

If from now on I get the editor value with editor.body.innerHTML, could problems occur?
Or what can I do so editor.value() doesn't automatically add spaces?

Thanks

 


<textarea id="editor"></textarea>
<script>
$("#editor").kendoEditor({ tools: [
    "bold", "italic", "underline", "fontName", "fontSize"
  ]});
var editor = $("#editor").data("kendoEditor");
$(editor.body).focus(function (e) { editor.exec("fontName", { value: "Tahoma" }); editor.exec("fontSize", { value: "10pt" }); var content = editor.value(); if (content.indexOf('<p') !== 0) editor.value('<p>'+ content +'</p>'); console.log(editor.value()); console.log(editor.body.innerHTML); });
</script>


Result:
editor.value():  <p><span style="font-family:Tahoma;font-size:10pt;">&nbsp;</span></p>
editor.body.innerHTML:  <p><span style="font-family:Tahoma;font-size:10pt;"></span></p>

1 Answer, 1 is accepted

Sort by
0
Yordan
Telerik team
answered on 09 May 2024, 08:21 AM

Hello Sebahattin,

Thank you for the provided details.

This is the expected behavior of the Editor component.

I see no issues with using the innerHTML property if that works for your case.

If you face any issues, please let us know. 

    Regards,
    Yordan
    Progress Telerik

    Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
    Sebahattin
    Top achievements
    Rank 1
    Iron
    commented on 13 May 2024, 06:43 AM

    Hello Yordan,
    thank you for the answer
    Regards
    Tags
    Editor
    Asked by
    Sebahattin
    Top achievements
    Rank 1
    Iron
    Answers by
    Yordan
    Telerik team
    Share this question
    or