javascript - addClass breaks JS -


i wrote following code:

document.addeventlistener("domcontentloaded", ()=>{     let menu = document.queryselector(' #menu-mainmenu ');     menu.style.display = 'none'; });  let newbutton = document.createelement(' div '); 

this code didn't cause problem.

the moment i've added following code right under let newbutton, suddenly, seems, js broke (no js load anywhere in site).

newbutton.classname = 'menubutton'; 

console returns error:

uncaught domexception:

failed execute 'createelement' on 'document':

the tag name provided (' div ') not valid name.

why happen? problem creating div element way?

you have spaces around div tag , cause error. remove them

document.addeventlistener("domcontentloaded", ()=>{      //let menu = document.queryselector(' #menu-mainmenu ');      //menu.style.display = 'none';      console.log('worked !!!');  });    let newbutton = document.createelement('div');  newbutton.classname = 'menubutton';


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -