Detecting tinyMCE textareas with JQUERY

会有一股神秘感。 提交于 2019-12-13 16:21:12

问题


On some of our forms we convert our textareas over to tinyMCE textareas. How can I tell in jquery if a given textarea has been converted?

I've notice that tinyMCE will change the display of my original textarea to none upon init and then creates an adjacent span with a class of mceEditor, but the follow jquery statements never seems to find it.

if ( $(formElm).siblings("span .mceEditor").size() > 0) { ...do this};

or

if( $(formElm).parent().find("span .mceEditor").length > 0 ) {...do this};

or

if( $(formElm).parent().children("span .mceEditor").size() > 0 ) {...do this};

[EDIT]

There was a request for what the textarea looks like after tinymce is done with it. Here goes

<td class="fields">
<textarea id="serviceDesc" class="form req blob" style="display: none;"> Warm and yummy in your tummy<br /></textarea>
<span id="serviceDesc_parent" class="mceEditor defaultSkin">
<table id="serviceDesc_tbl" class="mceLayout" cellspacing="0" cellpadding="0" style="width: 400px; height: 152px;">
<tbody>
<tr class="mceFirst">
<td class="mceIframeContainer mceFirst mceLast">
<iframe id="serviceDesc_ifr" frameborder="0" src="javascript:""" style="width: 100%; height: 129px;">
<html>
</html>
</iframe>
</td>
</tr>
<tr class="mceLast">
</tr>
</tbody>


回答1:


Quick tip: It may be that you've put a space after the span (in the selector), which makes jQuery look for an element with a class named "mceEditor" in the span.




回答2:


does $('span.mceEditor+textarea:hidden') do it? this assumes by 'adjacent' you mean the mceEditor span immediately precedes the text area (ala FCKeditor)




回答3:


Will work with if ( $(formElm + ' span.mceEditor').size() > 0) { ...do this};




回答4:


I tried the following and it works, If I want to check on a textarea with the id 'tmce', then I appended '_parent' to it and tested it thus:

if( $("#tmce_parent").size() )
{
//code in case of a textarea with tinymce
}



回答5:


Can you add a sample of the textarea and span?



来源:https://stackoverflow.com/questions/620065/detecting-tinymce-textareas-with-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!