javascript - Creating anonymous functions inside conditional statements -


i've snippet :

if(el) {     el.addeventlistener("click", function(){         if (body.classlist.contains("el-is-open")) {             body.classlist.remove("el-is-open");         } else {             body.classlist.add("el-is-open");         }     });      foo.addeventlistener("click", function(){         body.classlist.remove("el-is-open");     }); } 

is okay wrap these statements inside condition? i'm new js i'm not sure if okay do..

before got:

uncaught typeerror: cannot read property 'addeventlistener' of null 

after can have js inside same file, , run if document have id el (i.e). thanks


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -