使用Java脚本更改元素ID? [英] Change element ID using Javascript?
本文介绍了使用Java脚本更改元素ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<div id="content">
Content
</div>
如何使用Javascript更改此div的ID?
How would I change the ID of this div using Javascript?
推荐答案
是在Google搜索的第一个结果上发现的:
Found this on the first result on a Google search:
document.getElementById("originalDivId").setAttribute("id", "newDivId");
getElementById
完全按照其说的进行操作,它获取具有指定ID的元素的信息. setAttribute
更改HTML元素的属性,即HTML标记(例如class=""
,id=""
,style=""
等)中的内容.
getElementById
does exactly what it says, it obtains the information of an element with the Id specified. setAttribute
changes a HTML element's attribute, that is the stuff inside of the HTML tags (e.g. class=""
, id=""
, style=""
, etc).
这篇关于使用Java脚本更改元素ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文