1

Тут html данные.

var html_data = $('#html-editor-' + id).code();

Сам блок кода. Задача пройтись по всем совпадениям, извлечь из них нужное, затем перейти к родителю, его очистить, и вставить свою строку. И собственно вернуть уже модифицированный HTML

$.each($(html_data).find('script[type="math/tex"]'),function() {
         var equation = $(this).text(); // нужная строка, она тут есть
         var id_block =  $(this).parent().attr('id'); // на всякий случай id  то же есть

    $(html_data).html($('#'+id_block).replaceWith('privet')); // магия не получилась
    $(this).parent().empty(); // то же не выгорело
    $(html_data).find('#'+id_block).replaceWith('privet'); // ну и тут то же
                });

var html_data = '<p><br></p><div id="equation-25258" class="badge equation-container"><div class="privet"><script type="math/tex" id="MathJax-Element-3">\sqrt[n]{x}</script></div>';

$.each($(html_data).find('script[type="math/tex"]'),function() {
         var equation = $(this).text(); 
         var id_block =  $(this).parent().attr('id');

     //   $(html_data).html($('#'+id_block).replaceWith('privet')); 
        $(this).parent().empty(); 
        $(html_data).find('#'+id_block).replaceWith('privet');
});


$('.button').on('click', function() {
		$('.result').html(html_data);
});
.button {
  cursor:pointer;
  padding:10px;
  border-radius:5px;
  border: 1px solid black;
  width: 60px;
  
}
<div class="result">privet</div>

<p></p>
<div class="button">button</div>

2
  • выше объявленная $(html_data) не проходит, нужно попробовать найти атрибут, а потом уже код, + такое $.each($(html_data).find('script[type="math/tex"]'), function() тоже вряд ли пройдет 17 окт 2016 в 21:29
  • Поправил код, есть еще здесь jsfiddle.net/ch1cggod/3 правда ругается на присутствие в строке скрипта 17 окт 2016 в 21:57

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.