javascript - JS - Not accessing classes by their class name -


i working on to-do list app firebase, code supposed access element class name of 'close' not access any. if console log it, returns: {};

i using loop add onclick event, cannot add of elements if arry emtpy.

var config = {    apikey: "aizasybiv0dppiwuzadvgfmkipf7gsykivt8n4m",    authdomain: "to-do-332c9.firebaseapp.com",    databaseurl: "https://to-do-332c9.firebaseio.com",    projectid: "to-do-332c9",    storagebucket: "to-do-332c9.appspot.com",    messagingsenderid: "281739919235"  };  firebase.initializeapp(config);    const txtemail = document.getelementbyid('txtemail');  const txtpassword = document.getelementbyid('txtpassword');  const btnlogin = document.getelementbyid('btnlogin');  const btnsignup = document.getelementbyid('btnsignup');  const btnlogout = document.getelementbyid('btnlogout');  const addtodo = document.getelementbyid('addtodo');    var todoref;    btnlogin.addeventlistener('click', e => {      document.getelementbyid('form').classlist.add('hide');          const email = txtemail.value;    const pass = txtpassword.value;    const auth = firebase.auth();      const promise = auth.signinwithemailandpassword(email, pass);    promise.catch(e => console.log(e.message));      });    btnsignup.addeventlistener('click', e => {    const email = txtemail.value;    const pass = txtpassword.value;    const auth = firebase.auth();      const promise = auth.createuserwithemailandpassword(email, pass);    promise.catch(e => console.log(e.message));    });    btnlogout.addeventlistener('click', e => {    firebase.auth().signout();  });    firebase.auth().onauthstatechanged(firebaseuser => {    if (firebaseuser) {      btnlogout.classlist.remove('hide');      document.getelementbyid('form').classlist.add('hide');      document.getelementbyid('todo').classlist.remove('hide');      todoref = firebase.database().ref(firebaseuser.uid);      displaytodos();    } else {      btnlogout.classlist.add('hide');      document.getelementbyid('todo').classlist.add('hide');    }  });    addtodo.addeventlistener('click', () => {    var todo = document.getelementbyid('todoinput').value;    savetodo(todo);  });  /* window.onbeforeunload = function (e) {    var e = e || window.event;      if (e) {      firebase.auth().signout();    }      return firebase.auth().signout();;  }; */      function savetodo(todo){    var newtodoref = todoref.push();    newtodoref.set({      todo: todo    });  }     function displaytodos() {    todoref.on('value', gotdata, errdata);  }     var k;    function gotdata(data) {    var todos = data.val();    var keys = object.keys(todos);    var todolist = document.getelementbyid('todolist');        todolist.innerhtml = "";    (var i=0; i<keys.length; i++){      k = keys[i];      var todo = todos[k].todo;      todolist.innerhtml += "<li id='"+keys[i]+"'>"+todo+"<button id="+keys[i]+" class='close' style='margin-left='50px'>delete</button></li>";                      }  }    var close = document.getelementsbyclassname('close');  console.log(close);  (var = 0; < close.length; i++) {    var id = close[i].id;    close[i].onclick = function() {      var div = this.parentelement;      todoref.child(id).remove()    }  }    function errdata(err) {    console.log('error!');    console.log(err);  }


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 -