Luiz Alves
Luiz Alves

Reputation: 2645

Jquery to get all textarea elements with specific data

I have a a html with many textarea elements.

I need select all them, take your id to use in a JQuery function and set a text editor.

Here is what I did, but I have no success with my JS.

HTML:

  <textarea id="editor1" name="namedit1"
        data-editor="ck">
    </textarea> 
    <textarea id="editor2" name="namedit2"
        data-editor="ck">
    </textarea> 
    ....
    <textarea id="editorN" name="nameditN"
        data-editor="ck">
    </textarea> 

JS:

$("textarea").find(['data-editor="ck"']).each(
            function(){  
                    var input = $(this);
                    CKEDITOR.replace( input.id), {
                        uiColor: '#9AB8F3'
                    };
            });

Upvotes: 1

Views: 2771

Answers (2)

AndreFeijo
AndreFeijo

Reputation: 10649

Change your selector to $("textarea[data-editor=ck]") and make sure it's called on the page ready event.

Working demo: https://jsfiddle.net/52wb240h/

Upvotes: 0

Andr&#233;s Andrade
Andr&#233;s Andrade

Reputation: 2223

You are trying to find a text area element inside the text area.

Try with:

$('textarea[data-editor="ck"]').each(function(){  
                CKEDITOR.replace($(this).attr('id')), {
                    uiColor: '#9AB8F3'
                };
 });

Upvotes: 1

Related Questions