2012-10-31 26 views
-1

如何將<footer id="tt"></footer>更改爲<div id='tt'></div>使用jQuery 是否有方法可以輕鬆更改標記? 非常感謝jQuery html5標記更改爲div

+1

通過在谷歌做一個簡單的搜索,我得到http://stackoverflow.com/questions/ 7380137/jquery-change-tag – dchhetri

+0

btw,可以更改jquery對象的標籤,例如,如果我們需要更改使用$(selector).clone(true)接收的DOM對象的標籤,或者更好地克隆所有它是新的對象的孩子?如果需要處理與原始對象相同的事件呢? –

回答

2

您可以使用replaceWith方法:

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

您可以使用replaceWith()

var $foot=$('#tt'), html=$foot.html(); 

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