How to remove the a tag in javascript: first find the corresponding js code part; then pass "str.replace(/()|()/g, '') ;" method can remove the a tag.
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
How to remove the a tag in javascript?
Specific question:
js to remove the a tag and leave the content
How to use regular rules to remove the a tag and leave only the content http:/ /git.oschina.net
The way to replace the a tag part with empty is not to directly take the content of the a tag, because there are a lot of such codes, and there are other codes that need to be left in place
<a href="http://git.oschina.net/" style="box-sizing: border-box; color: rgb(51, 51, 51); text-decoration: none; transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1); -webkit-transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1); max-width: 100%; transparent;"><span data-wiz-span="data-wiz-span" style="box-sizing: border-box; max-width: 100%; font-size: 14pt;">http://git.oschina.net</span></a>
Implementation method:
(<\/?a.*?>)|(<\/?span.*?>)
That is:
str.replace(/(<\/?a.*?>)|(<\/?span.*?>)/g, '');
Running results
##[Recommended learning:javascript advanced tutorial】
The above is the detailed content of How to remove a tag in javascript. For more information, please follow other related articles on the PHP Chinese website!