tinyMCE エディターでは、自動的に入力したテキストが でラップされますが<p>
、これで問題ありません。それにクラスを追加したいだけです<p>
。
注: すべての p 要素にクラスを追加したくはありません。ユーザーがクリックして入力を開始する場所だけです。
どんな助けでも本当に感謝しています。
この目的には、tinymce javascript API を使用する必要があります。
editor = tinymce.get('your_editor_id');
$(editor.selection.getNode()).parents('p:first').addClass('your_class');
jquery以外のソリューションは次のとおりです。
editor = tinymce.get('your_editor_id');
editor.selection.getNode().closest("p:first").setAttribute("class", "your_class");
これを試して:
var tmceIframe = $(".mceIframeContainer iframe")[0].contentDocument || $(".mceIframeContainer iframe")[0].contentWindow.document;
$(tmceIframe).find("p").addClass("test")
または1行として:
$($("iframe")[0].contentDocument || $("iframe")[0].contentWindow.document).find("p").addClass("test")
2 番目の例では、iframe に直接移動して短くしていますが、ページに複数の iframe がある場合、これは問題になる可能性があります。ラッパーのように、要素 ID を使用して指定することをお勧めします。