Programatically remove HTML element within Editor

3 posts, 1 answers
  1. Tyler
    Tyler avatar
    47 posts
    Member since:
    Nov 2013

    Posted 05 Oct Link to this post

    I use the Kendo UI Editor using the MVC like this:

    @(Html.Kendo().EditorFor(m => m.Content)
    .Name("Content")
    .Encode(false)
    .Immutables(true)
    .StyleSheets(css => css
      .Add(Url.Content("~/Content/dfw/dfTemplateEditor.css"))
    )
    .HtmlAttributes(new { style = "width:100%;height:100%;min-height:100%" })
    .Events(events => events
      .Select("templateEditor_onSelect")
    )
    .Resizable(resizable => resizable.Content(true).Toolbar(true))

     

    I have html in the editor like this:

    <h1 style="text-align:left;"><strong>Title</strong></h1>
    <div id="xxx">HELP ME I WANT REMOVED!</div><p> </p>
    <h1 style="text-align:left;"><strong>Another Title</strong></h1>

     

    I want to programatically remove the div where id="xxx" but cant get it to work.

    I've tried the following all didn't work:

    var editor = $("#Content").data("kendoEditor");
     
    //NOTE event looking for the named element fails
     if ($('#xxx').length > 0) {
        //never gets here..
        alert('I EXIST!');
     }
     
    //Failed Attempt 1
    $('#xxx').remove();
    editor.update();
     
    //Failed Attempt 2
    editor.body.remove($('#xxx'));
    editor.update();

     

     

     

  2. Answer
    Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 05 Oct Link to this post

    Hello,

    Here is how to obtain reference to the Editor body, find the element and delete it:

    var editorBody = $("#editor").data("kendoEditor").body;
    $(editorBody).find("#xxx").remove();


    Best regards,
    Rumen
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
     
  3. Kendo UI is VS 2017 Ready
  4. Tyler
    Tyler avatar
    47 posts
    Member since:
    Nov 2013

    Posted 05 Oct in reply to Rumen Link to this post

    Thats what I was looking. Thanks!
Back to Top