Home  >  Article  >  Web Front-end  >  jQuery method to replace the specified string in the specified element_jquery

jQuery method to replace the specified string in the specified element_jquery

WBOY
WBOYOriginal
2016-05-16 16:09:051460browse

The example in this article describes how jQuery replaces the specified string in the specified element. Share it with everyone for your reference. The details are as follows:

This JS code can replace the string of the element content with the specified id. For example, the code in the west replaces the jb51 string in the id=content element with the empty character

The html part is as follows:

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

The jQuery part is as follows:

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

I hope this article will be helpful to everyone’s jQuery programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn