Replace Radhe to krishna
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<span>Jai shree Radhe</span>
</span>
</span>
<button class="btn btn-success mt-2">Click</button>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script>
$('button').click(function(){
var text =$('span').text();
var newText = text.replace(/(shree)[^\&]+/,'$1'+' Krishna');
console.log(newText);
$('span').text(newText);
//change click button background color
$(this).css('background-color','green');
});
</script>
Output
Jai shree Radhe
Comments
Post a Comment
If you any doubt of any topic then you can comment me.