Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can codemirror find textareas by class?

A good start

I asked this question "Codemirror - Use on multiple textareas?" a few years ago with a good answer. However, it still takes an ID as parameter. IDs are unique.

Find textarea by class instead of ID

When having multiple textareas, some with HTML and some with CSS on the same page, it would be nice to add a class instead of an ID.

Example

<p>Some content</p>

<textarea class="my_codemirror_html">
</textarea>

<p>Some content</p>

<textarea class="my_codemirror_html">
</textarea>'

If I can use jQuery for it, it's fine. I use that anyway on the page.

Update 2012-02-21 - Almost there

I found this post on jsFiddle. The only thing missing is that I can't make it work on textareas.

like image 607
Jens Törnell Avatar asked Nov 30 '22 03:11

Jens Törnell


1 Answers

This will be an easier solution with less complexity.

$('.my_codemirror_html').each(function(index, elem){
      CodeMirror.fromTextArea(elem, {/*options*/});
});
like image 144
Faraj Farook Avatar answered Dec 11 '22 00:12

Faraj Farook