有没有办法使用Jquery删除覆盖数字的预标签?
例如,我有以下内容:
<pre>1000</pre>
我需要使用Jquery删除PRE标签..
我该怎么做?
提前致谢...
答案 0 :(得分:4)
(请注意,David Thomas提供了一个如何将.unwrap()
与firstchild
一起使用的好例子。)
$("pre").wrapInner('<div>').find('div').unwrap();
你也可以这样做:
$("pre").parent().each(function(){
$(this).text($(this).text());
});
答案 1 :(得分:2)
我认为以下方法可以解开textNode:
$('pre').each(function(){
$(this.firstChild).unwrap();
});
因为我不知道所有 pre
元素是纯数字的,所以我添加了if
检查以查看该元素是否包含alpha字符(az,大写和小写):
$('pre').each(function(){
var text = $(this).text();
if (text.match(/[a-z]/gi)){
// you've got a string with letters
}
else {
$(this.firstChild).unwrap();
}
});
答案 2 :(得分:1)
答案 3 :(得分:0)
$("#element").html($("#element").html().replace(/<\/?pre>/i, ''));