替换特定的标签名称javascript [英] replace specific tag name javascript

查看:68
本文介绍了替换特定的标签名称javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我们是否可以更改标记中的标记名称而不是其内容。我有这个内容

I want to know if we can change tag name in a tag rather than its content. i have this content

< wns id="93" onclick="wish(id)">...< /wns>    

在愿望功能中我想将其更改为

in wish function i want to change it to

< lmn id="93" onclick="wish(id)">...< /lmn>

我试过这种方式

document.getElementById("99").innerHTML =document.getElementById("99").replace(/wns/g,"lmn")

但它不起作用。
plz请注意,我只想更改具有特定ID而不是每个wns标签的特定标签..

but it doesnot work. plz note that i just want to alter that specific tag with specific id rather than every wns tag..

谢谢。

推荐答案

document.getElementById("93").outerHTML = document.getElementById("93").outerHTML.replace(/wns/g,"lmn");

FIDDLE

这篇关于替换特定的标签名称javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆