[SOLVED] javascript - getElementById

I need help from a javascript developer.
I’m creating many dynamical input elements using js function appendChild. When i want to get id by using function getElementById, it doesnt work. What am I doing wrong?

1 Like

please share your code so we can understand more

make sure you are setting the id when creating the element like that :

var myDiv = document.createElement("div");
myDiv.id = "article-1";
var parent = document.getElementsByTagName("body")[0];
var myCreatedDiv = document.getElementById("article-1");

First of all its really hard to help without seeing any code, second you need to select the element you are trying to append to then append the child elements, third getElementById is meant to get only one element by id if you are trying to select multi elements use document.querySelectorAll.

1 Like

Read the FAQ before asking any question.

search at google and follow resources to contact any coder. Good luck!

I have solved problem using two functions. One for creating elements by createElement and appendChild.
The second function I used getElementById. I got the id dinamically. I used loop thats look like …‘id’+i .
Sorry for bad English and sorry if I had broken some rules of the Onehack.us.