javascript - How to check whether CKEditor has some text in it? -


I have an HTML form with some fields. One of them is a Texter managed by CkAditator.

When the user wants to submit the form, I want to check whether he is entering the values ​​in all areas or not.

I know how I can check that there is anything in the CKAdit controller, but it can contain "empty" HTML tags without any text.

How do I check for text?

The server side is using something like PHP trim (Strip_tags ($ content)), so I have to do the same in javascript.

A solution using jQuery would also be useful.

This will work:

  $ ("# editorContainer iframe" ). material (). Find ("body"). Text ();  

This will not only contain text and any html tags.

UPDATE

It definitely works but on. Use Firefox and Firebug, go to the Firebug console, and type:

  $ ("# demoInside iframe"). material (). ("Body").  

Will not print the text in the console editor, without any html tags. Make sure the selector is right in your particular application. You can test your selector like this:

  $ ("# demoInside iframe"). material (). ("Body") Length;  

It should be equal to 1. If this is 0, then your selector is wrong.

Update 2

Again, my code is still correct, and it still works on that page. All you need is the right selector, the page you link to, it's a is with ID cke_editor1 . This particular page does not use jQuery, so some extra work is required to prove the work of this sample. Install this page "jqueryify", and then do it in the Firebug console (note that you do not have to use jQuery and $ ). ).

  jQuery ("# ​​cke_editor1 iframe"). material (). Find ("body"). Text ();  

In short, make sure that you have the right selector to go to iframe regardless of whether you have a & lt; Div & gt; or & lt; Textarea & gt; Make your own CKEditor from is not important unless you have & lt; Iframe & gt; , then CKEditor has entered the DOM, you can use .contents (). ("Body") Search To get the text of that iframe, have you tested your jquery selector to see if .length == 1 ?


Comments