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
Post a Comment