【问题标题】:jQuery html5 tag change to divjQuery html5 标签更改为 div
【发布时间】:2012-10-31 02:43:11
【问题描述】:

如何使用 jQuery 将 <footer id="tt"></footer> 更改为 <div id='tt'></div> 有没有办法轻松更改标签? 非常感谢

【问题讨论】:

  • 通过在谷歌上进行简单搜索,我得到stackoverflow.com/questions/7380137/jquery-change-tag
  • 顺便说一句,可以更改 jquery 对象的标签,例如,如果我们需要更改使用 $(selector).clone(true) 接收的 DOM 对象的标签,或者更好地克隆所有是新对象的孩子吗?如果需要处理与原始对象相同的事件怎么办?

标签: javascript jquery


【解决方案1】:

你可以使用replaceWith方法:

$('#tt').replaceWith(function(){
   return '<div id="' + this.id + '"></div>'
})

【讨论】:

    【解决方案2】:

    您可以使用replaceWith()

    var $foot=$('#tt'), html=$foot.html();
    
    $foot.replaceWith( $('<div id="tt">').append(html) )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-14
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多