Where is the error in the code here?

  • 0
    div.onclick = function() {
                div.classList.toggle('complete');
                var allComplete = document.querySelectorAll('complete');    
                if(allComplete.length > 0){
                   countingEl.innerHTML =
                        '<div class="section-count" id="counting">Выбранно:'+allComplete.length+'</div>'
                    console.log(allComplete.length);
                }
    
                else{
                    countingEl.innerHTML =
                        '<div class="section-count" id="counting"></div>'
                    console.log(allComplete.length);
                }
            };
    JavaScript Anonymous, Sep 19, 2019

  • 3 Answers
  • 0
    document.querySelectorAll ('complete')


    There should be one more point here. Or querySelectorAll should give way to getElementsByClassName.
    Anonymous

  • 0
    In document.querySelectorAll you are looking for a tag called "complete" and not a tag with class "complete", add a period before complete
    Anonymous

  • 0
    You are looking for the "COMPLETE" tag in document.querySelectorAll , but you need a tag with the ".COMPLETE" class.



    here is the code without error:
    var allComplete = document.querySelectorAll('.complete');
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!