jQuery method to replace a specified string in a specified element

  • 2020-05-17 04:43:39
  • OfStack

This article demonstrates an example of how jQuery replaces a specified string in a specified element. Share with you for your reference. The details are as follows:

This JS code replaces the string that specifies the element content of id, for example, the western code replaces the jb51 string in the id=content element with a null character

The html section is as follows:


<div id=content>welcome to jb51</div>

The jQuery section is as follows:


var el = $('#content'); 
el.html(el.html().replace(/jb51/ig, ''));

I hope this article is helpful for you to design the jQuery program.


Related articles: