I can not replace the string.
The String comes from a textarea
Here the JSFiddle
value.replace('[Bold]', '<strong>');
I can not replace the string.
The String comes from a textarea
Here the JSFiddle
value.replace('[Bold]', '<strong>');
The problems with you code are
g
flag is RexExp[]
and /
should be escaped using \
in RegExpvalue.replace(...)
will not change orginal string $('.description:not(.focus)').keyup(function(){
var value = $(this).val();
var contentAttr = $(this).attr('name');
value = value.replace(/\[Bold\]/g, '<strong>');
value = value.replace(/\[\/Bold\]/g, '</strong>');
value = value.replace(/\[Italic\]/g, '<em>');
value = value.replace(/\[\/Italic\]/g, '</em>');
value = value.replace(/\[Underline\]/g, '<u>');
value = value.replace(/\[\/Underline\]/g, '</u>');
$('.'+contentAttr+'').html(value.replace(/\r?\n/g,'<br/>'));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
start typeing in textarea whatever text you type it will also apear in div which has class <strong>'content'</strong> but when I press enter for new line in textarea when i get the problem div named <strong>'content'</strong> will not making new line please help
<br/>
<textarea name="description" rows="15" class="description"></textarea>
<p> </p>
<div class="description" >Texts Comes here</div>