[英]Replace all instances of a character in multiple elements
<div class="example">Some example text</div>
<div class="example">Some more example text</div>
How can I remove all instances of the letter 'e' (case sensitivity not necessary) in the elements above without preexisting ids? 如何在没有预先存在的ID的情况下删除上述元素中字母“e”的所有实例(不必要区分大小写)?
$('div').each(function() {
this.innerHTML= this.innerHTML.replace(/e/g, '');
});
If you want e
or E
use this: 如果你想要e
或E
使用这个:
$('div').each(function() {
this.innerHTML= this.innerHTML.replace(/e|E/g, '');
});
If there are elements inside those <div>
s use the text
function to get only the textNodes: 如果这些<div>
有元素,则使用text
函数只获取textNodes:
$('div').each(function() {
$this = $(this);
$this.text($this.text().replace(/e|E/g, ''));
});
Assuming you want to replace the content of the inner text (and not generically all the 'e's inside the tag): 假设您要替换内部文本的内容(而不是通常标记内的所有'e'):
$(yourselector).each(function(){
$(this).text($(this).text.replace(/e/g, ''));
});
PS Corrected after gdoron remark... PS纠正gdoron评论后......
var de = document.documentElement;
de.innerHTML = de.innerHTML.replace(/>.*?</g, function(a, b) {
return a.replace(/e/g, "f");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.