如何动态设置html元素的修改ID

时间:2013-10-28 16:01:07

标签: javascript

我有如下文本框元素:

<input type="text"  class="url" id="url" name="url" contenteditable="true"  style=" text-align: left; height: 30px; width:512px; " placeholder="Enter URL ..."/></input>

当用户执行按钮点击操作时,在被调用的函数中我想更改文本框的ID。

是否有类似

的内容

document.setElementID?

我已经创建了输入元素,所以这没有帮助:

var hiddenInput = document.createElement("input");
    hiddenInput.setAttribute("id", "uniqueIdentifier");

1 个答案:

答案 0 :(得分:2)

var hiddenInput = document.getElementById ('url');
hiddenInput.id = 'uniqueIdentifier';

或使用jquery:

$('#url').attr('id','uniqueIdentifier');