Jsz Jsz - 1 month ago 5
HTML Question

Replace <table> with { and </table> with } inside textarea

I have HTML code inside textarea and I want to replace using jQuery

<table>


with

`{`


and

`</table>`


with

`}`




textarea {width:500px;height:400px;}

<textarea>
<table>
<tr>
<td>content</td>
<td>content</td>
<td>content</td>
<td>content</td>
<td>content</td>
<td>content</td>
</tr>
<tr>
<td>content</td>
<td>content</td>
<td>content</td>
<td>content</td>
<td>content</td>
<td>content</td>
</tr>
</table>
</textarea>





As a fiddle.

Answer

Use String.prototype.replace

var el = $('textarea');
el.val(el.val().replace(/<table>/g, '{').replace(/<\/table>/g, '}'));