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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:44:57+00:00 2026-06-16T09:44:57+00:00

I’m having some problems to apply a background-color in the textarea of a ckeditor

  • 0

I’m having some problems to apply a background-color in the textarea of a ckeditor instance.

When the user clicks on submit without adding any text, it’s shown a message telling him to fill all the required fields, and these required fields areas all with the text-fields set with background-color: #CFC183;.

As the ckeditor is created with javascript code, I was using it to try to check if there’s any text entered in the text area. if there’s no character, I apply the changes.
When I apply in the console this code:

CKEDITOR.instances.body.document.getBody().setStyle('background-color', '#CFC183');

It applies the background exactly like I want to.
So, I added this javascript code in my javascript file to try to manage it, but doesn’t seems to be working. Here’s my code:

var editorInstance = CKEDITOR.replace('body', { toolbar : 'Full' });
editorInstance.on("instanceReady", function (ev) { 
    var editorCKE = CKEDITOR.instances.body; readyMap[editorCKE] = true;
    editorCKE.setReadOnly(true); 
});
var hasText = CKEDITOR.instances.body.document.getBody().getChild(0).getText();
if (!hasText) { 
    CKEDITOR.on('instanceCreated', function(e) { 
        e.editor.document.getBody().setStyle('background-color', '#CFC183');
    });
}

Firebug shows this error message:

TypeError: CKEDITOR.instances.body.document is undefined

I’m not that good at Javascript, so is there anything wrong with my code?
I already checked this question here, so I believe there’s something wrong with my javascript code and I want your help, please.

  • 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-16T09:44:59+00:00Added an answer on June 16, 2026 at 9:44 am

    I guess that you’ve got an error in this line:

    var hasText = CKEDITOR.instances.body.document.getBody().getChild(0).getText();
    

    This is because you’re trying to get document element before it’s ready (before instanceReady event).

    The same error will be thrown here:

    if (!hasText) { 
        CKEDITOR.on('instanceCreated', function(e) { 
            e.editor.document.getBody().setStyle('background-color', '#CFC183');
        });
    }
    

    Again – instanceCreated is still too early. You have to move all that code to instanceReady listener. You’ll have something like (I’m not sure if I understand what you’re trying to achieve):

    var editor = CKEDITOR.replace( 'body', { toolbar: 'Full' } );
    editor.on( 'instanceReady', function( evt ) {
        readyMap[ editor.name ] = true;
        editor.setReadOnly( true ); 
    
        var hasText = editor.document.getBody().getFirst().getText();
        if ( !hasText ) { 
            editor.document.getBody().setStyle( 'background-color', '#CFC183' );
        }
    } );
    

    As you can see, there is one more issue in your code:

    readyMap[editorCKE] = true;
    

    In JS there are no weak maps (yet, but they will be introduced soon). Only strings can be used as a keys of an object. In your case toString() method will be called on editorCKE, which returns [object Object]. That’s why I added name property there.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I need to clean up various Word 'smart' characters in user input, including but
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.