これは、 を実行する.mathquill('latex', info)
と、エディターを使用するために必要な要素も削除されるために発生するようです。エディター ( $('.mathquill-editor')
) が機能するには、最初の 2 つの子が必要です。残りは mathquill の一部です。
主なクリア方法は以下の通りです。
while ($('.mathquill-editor').children().length > 2)
$('.mathquill-editor').children()[2].remove();
$('.mathquill-editor').addClass('empty');
ただし、上記のコードが別の Web サイトで機能しない場合や、クラス名が同じでない場合に備えて、より動的な方法も含めます。
JQuery
function clearEditor(elem) {
while ($(elem).children().length > 2)
$(elem).children()[2].remove();
$(elem).addClass('empty');
}
clearEditor('.mathquill-editor');
ピュア Javascript
function clearEditor(elem) {
while (document.querySelector(elem).children.length > 2)
document.querySelector(elem).children[2].remove();
document.querySelector(elem).setAttribute('class', document.querySelector(elem).getAttribute('class') + ' empty');
}
clearEditor('.mathquill-editor');