Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6550269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:11:44+00:00 2026-05-25T12:11:44+00:00

I have successfully managed to set up an on paste event to capture the

  • 0

I have successfully managed to set up an on paste event to capture the HTML pasted into the text area as it is pasted.

I need to automatically apply the removeFormat command to that HTML before or at the time it is pasted into the text area, so that I can strip it of classes, various tags, and other attributes. Could somebody point me in the right direction to apply the removeFormat command correctly?

Here’s my code so far:

$(function(){
        $('textarea').ckeditor(
            function( textarea ){
                var editor = this;
                editor.on('paste', function( e ) { 
                    //alert(e.data.html); // This shows the HTML
                    editor.execCommand( 'removeFormat', e.data.html ); // Doesn't seem to do anything, HTML is pasted with the attributes intact
                    });              
            }
        )
    });

Thanks!

P.S. Force plain text option is not viable as there are some HTML elements I wish to keep (p,table and others).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:11:44+00:00Added an answer on May 25, 2026 at 12:11 pm

    You need to select the content before you can apply removeFormat to it.

    You could try grabbing the range ( even if it’s just the cursor sitting at the insertion point ) and saving a bookmark before you paste.

    After you paste, use the bookmark to select that range again.

    That should select everything that you pasted between the start and end of the range.

    Then you can use removeFormat:

    editor.execCommand( 'removeFormat', editor.selection );
    

    Here are the links to the range and selection API pages:

    http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dom.range.html

    http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dom.selection.html

    I’ve found it easier to work with ranges, the createBookmark method is good because it sets markers and you can grab the correct start and end points even if the DOM changes ( as it will when you paste in the new content ). You can use moveToBookmark() after the paste to select the range.

    http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dom.range.html#createBookmark

    Because the documentation is sparse, I’ve found it helpful to search the source code for places where the methods are called. Looking at how they’re used gives me a better idea of what kind of object I need to apply the methods to.

    Be Well,
    Joe

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully managed to get System.Speech.Synthesis to read English text in arbitrary voices
Have anyone successfully managed to setup a combined Java/C++ project for Eclipse? What I
I have successfully implemented interop beftween Win32 application and managed .Net dll as described
After much fiddling, I've managed to install the right ODBC driver and have successfully
I have successfully set up FILESTREAM on my SQL 2008 server; however I've noticed
I have successfully managed to bind images stored in Isolated Storage to Image elements
I have my behaviours set up so that on successfully running a build, Xcode
We have successfully set up a couple of local package repositories using the NuGet.Server
I am using JQuery tabs in my page, and have successfully managed to place
I have successfully connected to an Oracle database (10g) from C# (Visual Studio 2008)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.