NicEdit not working on other textareas

0

I'm creating a kind of forum on my client's site. In this forum, to ask questions and comments, obviously use TextAreas.

However, I'm using the NicEdit class to transform my textareas with font choice, size, insertion of images and links etc. I've had to put the code like this:

<script src="http://js.nicedit.com/nicEdit-latest.js"type="text/javascript"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function () {
    var textareas = document.getElementsByName("postar");

    for(var i=0;i<textareas.length;i++)
     {
        var myNicEditor = new nicEditor();
        myNicEditor.panelInstance(textareas[i]);

     }

    //var textareas2 = document.getElementsByName("comentar");

    //for(var i=0;i<textareas2.length;i++)
    // {
    //    var myNicEditor = new nicEditor();
    //    myNicEditor.panelInstance(textareas2[i]);

    // }
});
</script>

So, my comments textareas are normal. What could I do to enable the comment textareas normally with NicEdit?

    
asked by anonymous 28.08.2017 / 16:10

1 answer

1

Add a class to the textarea you want to instantiate the editor:

<textarea class="meueditor" name="postar"></textarea>
<textarea class="meueditor" name="comentar"></textarea>

Then just simplify the code by searching for the name of class :

bkLib.onDomLoaded(function () {
    var textareas = document.getElementsByClassName("meueditor");
    var myNicEditor = new nicEditor();
    for(var i=0;i<textareas.length;i++)
    {
        myNicEditor.panelInstance(textareas[i]);
    }
});

You do not need to include var myNicEditor = new nicEditor(); inside the for loop. Just invoke it 1 time.

    
28.08.2017 / 17:52