jQuery addClass example

Change class name on click in jQuery

by saturngod

HTML

<section>
  <textarea id="mmcode">English [mm]jrefrmvdka&;[/mm]</textarea>
</section>
<section>
  <div id="render"></div>
</section>

CSS

#mmcode {
  width:100%;
  height:200px;
}

JavaScript

update()

function update() {
  txt = $("#mmcode").val()
  newtxt = render(txt)
  $("#render").html(newtxt)
}

$("#mmcode").on('keyup', function() {
  update()
})

function render(str) {
  let regex = /\[mm](.*?)\[\/mm]/gm;
  let subst = `<span style="font-family:'WinResearcher'">$1</span>`;
  return str.replace(regex, subst);
}