Skip to content

Instantly share code, notes, and snippets.

@guerbai
Last active June 2, 2019 04:08
Show Gist options
  • Save guerbai/9025758cfb2e34917d646a1185d05274 to your computer and use it in GitHub Desktop.
Save guerbai/9025758cfb2e34917d646a1185d05274 to your computer and use it in GitHub Desktop.
使用jquery替换chiild
$.prototype.replaceChildText = function (text) {
let textNodes = this.contents().filter(function() {
return this.nodeType === 3;
});
textNodes.each(function() {
if (this.nodeValue.trim() !== '') {
this.nodeValue = text
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment