仅将所有TABLE元素更改为TD标记内的DIV仅jQuery

我有一个TABLE结构,我想使用jQuery函数将其元素转换为DIV

HTML示例:

 
1000+  $0.115
2000+  $0.106
5000+  $0.099
10000+  $0.092
Some Data

我只想替换的结构是那些位于单元格( TD )标签内的表格。 因此,制作了一个代码来过滤和替换驻留在TD标记内的那些表

 $('table td:has(table)').replaceWith(function() { //Replace function starts here }) 

问题是我想将

等所有元素替换为
元素。

我怎样才能做到这一点?

 
1000+
  
$0.115
2000+
  
$0.106
5000+
  
$0.099
10000+
  
$0.092
Some Data

您可以使用以下内容:

 $("#me").click(function(){ var innerhtml = $("table tr td").html(); var innerhtml = innerhtml.replace(/table/g, "div"); var innerhtml = innerhtml.replace(/tbody/g, "div"); var innerhtml = innerhtml.replace(/tr/g, "div"); var innerhtml = innerhtml.replace(/td/g, "div"); $("table tr td").html(innerhtml); }); 

它从表内抓取HTML,并用“div”替换“table”,“tbody”,“tr”和“td”的所有实例。

这里的工作示例