您不能更改现有 DOM 元素的标签名称;相反,您必须创建一个替换,然后将其插入元素所在的位置。
其基础是将子节点移动到替换中,并类似地复制属性。例如:
var wns = document.getElementById("93");
var lmn = document.createElement("lmn");
var index;
// Copy the children
while (wns.firstChild) {
    lmn.appendChild(wns.firstChild); // *Moves* the child
}
// Copy the attributes
for (index = wns.attributes.length - 1; index >= 0; --index) {
    lmn.attributes.setNamedItem(wns.attributes[index].cloneNode());
}
// Replace it
wns.parentNode.replaceChild(lmn, wns);
现场示例:( 我使用divandp而不是wnsand lmn,并通过带边框的样式表对它们进行样式设置,以便您可以看到更改)
document.getElementById("theSpan").addEventListener("click", function() {
  alert("Span clicked");
}, false);
document.getElementById("theButton").addEventListener("click", function() {
  var wns = document.getElementById("target");
  var lmn = document.createElement("p");
  var index;
  // Copy the children
  while (wns.firstChild) {
    lmn.appendChild(wns.firstChild); // *Moves* the child
  }
  // Copy the attributes
  for (index = wns.attributes.length - 1; index >= 0; --index) {
    lmn.attributes.setNamedItem(wns.attributes[index].cloneNode());
  }
  // Insert it
  wns.parentNode.replaceChild(lmn, wns);
}, false);
div {
  border: 1px solid green;
}
p {
  border: 1px solid blue;
}
<div id="target" foo="bar" onclick="alert('hi there')">
  Content before
  <span id="theSpan">span in the middle</span>
  Content after
</div>
<input type="button" id="theButton" value="Click Me">
 
 
有关可重用功能,请参阅此要点。
旁注:我会避免使用id全是数字的值。尽管它们在 HTML 中有效(从 HTML5 开始),但它们在 CSS 中无效,因此您无法设置这些元素的样式,或者使用 jQuery 等使用 CSS 选择器与它们交互的库。