我有这行的HTML:
<FONT size=4>Hello</FONT>
<FONT size=5>Hello</FONT>
我想使用jQuery替换字体:
如果字体大小= 4替换为<h2 class="h2class">Hello</h2>
如果字体大小= 5替换为<h3 class="h3class">Hello</h3>
我一直试图像这样使用replaceWith()函数:
$('font').replaceWith('<h2 class="h2class"></h2>');
但是后来我丢失了文本,也无法完全确定如何检查字体大小。
因此,有两个问题:1.如何根据字体大小有条件地执行此操作。2.如何在不丢失原始文本的情况下执行此操作。
谢谢
尝试
$('font[size="4"]').replaceWith(function(){
return $('<h2 />', {"class": "h2class"}).append($(this).contents())
});
$('font[size="5"]').replaceWith(function(){
return $('<h3 />', {"class": "h3class"}).append($(this).contents())
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句