Skip to content
Advertisement

document.getElementById giving Null by JS not by HTML

When I am defining my input tag in html and accessing in JS by id then I am getting my tag.

HTML Code:

JavaScript

JS Code:

JavaScript

Here things are fine.

But When I am creating from javascript and trying to access I am getting. I want dynamic So I need to create from JS.

JS Code:

JavaScript

Here I am getting null after applying this:

JavaScript

Advertisement

Answer

You have to append your created element into the document using document.body.appendChild(input);

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement