I have a button which creates form elements on click .
My addelement function looks like this
function addElement(){
to = document.getElementById('top');
newId = document.createElement('div');
id = 'my'+this.num;
newId.setAttribute('id', id );
newId.innerHTML = "<input type = 'text' value = ''>";
to.appendChild(newId);
this.num++;
}
… which renders the text input field to a form with ID = ‘top’ and creates a dynamic div for every form element
Now once the element is inside the form, I want to know a way to edit that element. How could that be done?
As you assign
idto this element:You can get this element by id using
getElementByIdfunction:If you need to get
inputelement, simple write:But I will reccomend you to not create elements from string. ie:
the better is to use
createElementfunction and then append it to newly createddiv