[Solved] Editor still can't edit some HTML...

2 Answers 202 Views
Editor
Hugo Augusto
Top achievements
Rank 2
Iron
Iron
Veteran
Hugo Augusto asked on 21 Jun 2023, 01:24 AM | edited on 21 Jun 2023, 01:27 AM

Using an Editor demo available from the demos, switch to HTML view and paste the following HTML into it:

<div class="row g-3">
<div class="col-6">
<h4>Left column...</h4>
<br />
This selector will match any element that has a class attribute starting with "col-". For example, it will match elements with classes like "col-1", "col-2", "col-header", etc.<br />
<br />
</div>
<div class="col-6"><span>Right column...</span></div>
</div>

Now, switch again to the Design mode.

Try to add some text after the "Right column..." text by placing the cursor in the end of the text, pressing enter and writing something, or just try to change that text format into an H4.

Editor will insert a new paragraph with the col-6 class and outside that DIV!

Here's the result:

<div class="row g-3">
<div class="col-6">
<h4>Left column...</h4>
<br />
This selector will match any element that has a class attribute starting with "col-". For example, it will match elements with classes like "col-1", "col-2", "col-header", etc.<br />
<br />
</div>
<div class="col-6"><span>Right column...</span></div>
<p class="col-6"><span>Just want to add more text...</span></p> --> this should not be here!
</div>

How can this be fixed? Need to provide some snippets but they are unusable this way.

Thank you

Hugo Augusto
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 25 Mar 2026, 02:59 PM

2026 and no answers...

2 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 25 Mar 2026, 04:47 PM

Hi Hugo,

When NewLineMode is set to its default value "P", pressing Enter inside a <div class="col-6"> causes the editor to create a new <p> element and inherit the CSS class from the parent <div>. This results in <p class="col-6"> being inserted as a sibling — which is exactly what you're seeing.

Solution

Set ContentAreaMode="Div" and handle the OnClientCommandExecuted event to strip the inherited classes from newly created elements:

<telerik:RadEditor runat="server" ID="RadEditor1"
    ContentAreaMode="Div"
    NewLineMode="Div"
    OnClientCommandExecuted="onCommandExecuted">
            <Content>
<div class="row g-3">
<div class="col-6">
<h4>Left column...</h4>
<br />
This selector will match any element that has a class attribute starting with "col-". For example, it will match elements with classes like "col-1", "col-2", "col-header", etc.<br />
<br />
</div>
<div class="col-6"><span>Right column...</span></div>
</div>
            </Content>
        </telerik:RadEditor>

<script type="text/javascript">
    function onCommandExecuted(editor, args) {
        if (args.get_commandName() === "EnterNewLine") {
            var contentArea = editor.get_contentArea();
            var sel = editor.getSelection();
            var newDiv = sel.getParentElement();

            // Walk up to find the div that was just created by Enter
            while (newDiv && newDiv !== contentArea && newDiv.tagName !== "DIV") {
                newDiv = newDiv.parentNode;
            }

            if (newDiv && newDiv !== contentArea && /\bcol-\S*/.test(newDiv.className || "")) {
                newDiv.className = newDiv.className.replace(/\bcol-\S*/g, "").replace(/\s+/g, " ").trim();
                if (!newDiv.className) {
                    newDiv.removeAttribute("class");
                }
            }
        }
    }
</script>

Key points

  • ContentAreaMode="Div" — renders the content area as a <div> in the page, which keeps newly created elements within the layout structure.
  • OnClientCommandExecuted — fires after the EnterNewLine command (Enter key) allowing you to strip the inherited col-* classes from the newly created element.

Result

Before:

<div class="col-6"><span>Right column...</span></div>
<p class="col-6"><span>Just want to add more text...</span></p>

After:

<div class="col-6"><span>Right column...</span></div>
<p><span>Just want to add more text...</span></p>

Feel free to fine tune the EnterNewLine command to cover your scenario. 

Regards,
Rumen
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Hugo Augusto
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 30 Mar 2026, 07:42 PM

The issue with using Div instead of Iframe is that Editor will be polluted with all the css classes of the page it's placed, so not an ideal solution. Also, this js still does not work because now it clears the div css removing "col-6". I know if I tweaked the JS it could work but I'm sure there would be other issues later on. Never mind, we are switching to other solutions.
0
Rumen
Telerik team
answered on 30 Mar 2026, 08:08 PM

Hi Hugo,

Thank you for the follow-up.

About ContentAreaMode="Div" and Page Styles

The purpose of ContentAreaMode="Div" is specifically to allow page styles to apply to the editor's content area - this is by design and documented behavior. If you do not want page styles to affect the content area, keep the default ContentAreaMode="Iframe" and use CssFiles to load only the styles you need inside the editor:

<telerik:RadEditor runat="server" ID="RadEditor1"
    OnClientCommandExecuted="onCommandExecuted">
    <CssFiles>
        <telerik:EditorCssFile Value="~/my-editor-content-styles.css" />
    </CssFiles>
    <Content>
<div class="row g-3">
    <div class="col-6"><h4>Left column...</h4></div>
    <div class="col-6"><span>Right column...</span></div>
</div>
    </Content>
</telerik:RadEditor>

Place only the Bootstrap grid classes (.row, .col-*, etc.) you need in my-editor-content-styles.css. The CssFiles collection works with Iframe mode and gives you full control over what styles are rendered in the content area, without any page style leaking.

Enter Key — Preventing Class Inheritance on New Elements

The previous JavaScript stripped col-* from the new element unconditionally  even when Enter was pressed in the middle of text and the content was split across two elements. The version below adds a textContent check so that classes are only removed when the newly created element is empty (i.e., Enter was pressed at the end of text):

<script type="text/javascript">
    function onCommandExecuted(editor, args) {
        if (args.get_commandName() !== "EnterNewLine") return;

        var contentArea = editor.get_contentArea();
        var sel = editor.getSelection();
        var newElement = sel.getParentElement();

        // Walk up to the block-level element created by Enter
        while (newElement && newElement !== contentArea
            && newElement.tagName !== "P" && newElement.tagName !== "DIV") {
            newElement = newElement.parentNode;
        }

        if (!newElement || newElement === contentArea) return;

        // Only strip col-* from the NEW (empty) element
        var text = (newElement.textContent || newElement.innerText || "")
            .replace(/\u00A0/g, "").trim();

        if (text === "" && /\bcol-\S*/.test(newElement.className || "")) {
            newElement.className = newElement.className
                .replace(/\bcol-\S*/g, "")
                .replace(/\s+/g, " ").trim();
            if (!newElement.className) {
                newElement.removeAttribute("class");
            }
        }
    }
</script>

 

Summary

  • Iframe mode + CssFiles — keeps the content area isolated; load only the CSS you need.
  • Div mode — inherits page styles by design; this is documented and expected.
  • OnClientCommandExecuted — fires after the EnterNewLine command, letting you clean up only the newly inserted element.

Out of curiosity, you mentioned you are switching to other solutions. May I ask which rich-text editor you are considering for a WebForms (AJAX) project? Telerik UI for ASP.NET AJAX is one of the last actively maintained and developed commercial suite for this technology in 2026, so I'm genuinely curious what alternative you have in mind. Any feedback helps us understand what our customers need.

Regards,
Rumen
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Hugo Augusto
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 31 Mar 2026, 10:31 AM | edited

Hi Rumen,

The fix you posted falls apart when you try to insert a paragraph, a list or other kind of html elements. How would you fix that? As for the question about other solutions I mentioned previously, I already answered in my other post but I'll answer again here. First of all, don't get me wrong, Editor control, in my opinion was one of the best in class, but hasn't changed and evolved for the UX users expect nowadays. Editor control has stopped in time 5 years ago. I leave you a couple of examples similar to the solution we will be using instead of Rad Editor. The main evolution we are after is the possibility for the user to deal with html blocks (Divs. Headers, Paragraphs, images, Lists, tables, etc) using drag and drop with the option to also be able to insert already made blocks of content avoiding to create content from scratch. It's very important that this "editor" can deal properly with DIV elements and even support Bootstrap for columns and rows.

Rad Editor is still based on tables as the structure for all content and that is wrong. Even your samples use tables for structure making it unresponsive and not fit for mobile devices.

KEditor - Kademi Content Editor

Bootstrap grid - Frameworks - Examples - Redactor

givanz/VvvebJs: Drag and drop page builder library written in vanilla javascript without dependencies or build tools.

Rumen
Telerik team
commented on 31 Mar 2026, 01:32 PM

Thank you for the detailed feedback and for sharing those links, Hugo.  These three editors are great examples that clearly illustrate the editing experience you're looking for. This kind of input is very valuable to us.

We do have a feature request logged for this type of block-based, drag-and-drop layout editing in RadEditor:
Bootstrap Grid Builder for RadEditor.

If you haven't already, I'd encourage you to cast your vote and add your scenario as a comment there. The feedback portal is the primary mechanism we use to prioritize new features, and detailed real-world use cases like yours carry significant weight with the product team. I want to be upfront with you: this feature currently has very limited votes, so it is not on the near-term roadmap. Building a full block-based drag-and-drop content builder is a major engineering effort, and we need to see enough community demand to prioritize it.

We appreciate your long-time use of our components and your honest feedback.

Tags
Editor
Asked by
Hugo Augusto
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Rumen
Telerik team
Share this question
or