user123
user123

Reputation: 5407

How to set modify ID of html element dynamically

I have textbox element as below:

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

When user perform button click action, in called function I want to change the ID of textbox.

Is there anything like

document.setElementID?

I have already created input element so this will not help:

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

Upvotes: 0

Views: 72

Answers (1)

Bobby Shark
Bobby Shark

Reputation: 1074

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

or with jquery :

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

Upvotes: 2

Related Questions