изменить имя тега при сохранении содержимого и атрибутов
function changeTagName(elm,new_tag_name){
var newElm = document.createElement(new_tag_name)
var atr = elm.attributes;
for(var i=0;i<atr.length;i++){ // copy all atributtes
newElm.setAttribute(atr[i].name,atr[i].value)
}
document.body.insertBefore(newElm,elm)
newElm.innerHTML=elm.innerHTML; //copy the content
elm.parentNode.removeChild(elm) // remove original
}
например:
<span id='sp1' class='cl1 cl2'> some t e x t with (\n) gaps .... and etc</span>
changeTagName(document.getElementById('sp1'),'pre');