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 8703121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:48:26+00:00 2026-06-13T02:48:26+00:00

When creating new paragraphs in CKEditor the attributes (styles, classes) of the previous paragraph

  • 0

When creating new paragraphs in CKEditor the attributes (styles, classes) of the previous paragraph get copied onto the new one. Is there a way to prevent this?

For example, if I’m writing in a centered paragraph and press enter to create a new paragraph, my users want the new paragraph to be a simple

without “inheriting” anything from the previous by default.


Edit

I managed to get it (dangeriously untested) working with Reinmar’s tips. Here is what I wound up with; I hope this helps someone else. If you guys see a glaring error here, please do tell me

CKEDITOR.on('instanceCreated', function(e) {
    e.editor.on('key', function(evt) {
        if (evt.data.keyCode === 13) {
            // if we call getStartElement too soon, we get the wrong element
            setTimeout(function () {
                var se = e.editor.getSelection().getStartElement();
                if(se.getName() == "span") {
                    var text = se.getText(); // Store text, we are about to nuke the spans
                    while (se.getName() == "span") { // possible infinite loop danger
                        se = se.getParent();
                    }
                    if (text.length == 0)
                        se.setHtml(" "); // It's important that this is not empty
                    else
                        se.setHtml(text);
                }
                debug(se.getHtml());
                se.removeAttribute("class");
                se.removeAttribute("mycustomattr");
                se.removeAttribute("myothercustomattr");
                window.bla = se; // useful for debugging
            }, 10);
        }
    });
}); 
  • 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-06-13T02:48:27+00:00Added an answer on June 13, 2026 at 2:48 am

    I was thinking about your question for last two days and I’ve got an idea. I checked enter plugin code and it’d better to leave it untouched. Instead you can listen on enter key and after our custom enter is performed you should clear styles from newly created block.

    These methods will be useful:

    • editor.on( 'key', function( evt ) { evt.data.key... } )
    • editor.getSelection().getStartElement() – after enter selection start will be placed in newly created block (+ inline elements like bold, underline, etc).
    • CKEDITOR.dtd.* – sets of elements may help you making decision which elements are inline styles and should be removed.
    • element.isEmptyInlineRemoveable – you should remove empty inline elements in which cursor was placed.
    • editor.createRange().setStartAt( block, 0 ).select() – at the end you should place caret in correct place (at the beginning of block – <p>/<div>/<li>/etc.).

    Unfortunately, as you can see, this’s not an easy thing to write, so good luck 🙂

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

Sidebar

Related Questions

Other than creating new button background images, is there a way to set UIBarButtonItems
I'm creating a jquery animation and weirdly, when I append a new paragraph, it
When creating new class instance I get A first chance exception of type 'System.Deployment.Application.InvalidDeploymentException'
When creating new entities from user input I can't be sure that there is
when i am creating new android project from visual studio 2010 it gives the
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
When I'm creating new project with GWT plug in it creates a skeleton project
I'm creating new Site Definitions using this method: http://weblogs.asp.net/paulballard/archive/2007/04/09/creating-a-custom-sharepoint-2007-portal-site-definition-using-the-portalprovisioningprovider-class.aspx and when they get created,
I'm trying to establish workflows for creating new projects and for setting old projects
Can I avoid third party code from creating new threads, starting new VMs, or

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.