javascript - why is it giving error "appendChild is null" error and how do i fix it -


when trying append td element tr, throwing error:

cannot read property appendchild of null

this code:

var col = prompt('enter number of columns, table needs have'); var row = prompt('enter number of rows, table should have');  function columncreator() {     var table = document.queryselector('tablediv');     var tablerow = document.createelement('tr');     table.appendchild(tablerow);      (var = 0; < col; i++) {        var tabledata = document.createelement('td');        tablerow.appendchild(tabledata);        var dummytext = document.createtextnode('table data');        tabledata.appendchild(dummytext);     } }  columncreator(); 

var table = document.queryselector('tablediv'); console.log(table)//undefined 

theres nothing tablediv, either id,class, or nested structure:

var table =      document.queryselector('#tablediv') //id ||  document.queryselector('.tablediv') //class ||  document.queryselector('table > div') //div inside table ||  document.queryselector('div > table');//table inside div 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -