How do you get elements from a javascript HTMLCollection

后端 未结 3 1124
迷失自我
迷失自我 2021-02-07 04:30

I can\'t understand why I cant get elements from a HtmlCollection. This code example:

 var col = (document.getElementsByClassName(\"jcrop-holder\"));
 console.lo         


        
3条回答
  •  灰色年华
    2021-02-07 05:04

    look this code, with it you can use a class attribute for a HTMLColletion

      var eles = document.getElementsByClassName('className');
        for (let i = 0; i < eles.length; i++) {            
                eles[i].addEventListener('click',function(){
                    // code ex. eles[i].querySelector(".contenedor").classList.toggle('ocultar');
                    // code here...
                })
    
        } 
    

提交回复
热议问题