getElementByClassName Not Returning Results

前端 未结 2 523

My getElementByClassName() isn\'t returning any results, I had it set to getElementById(), but I can\'t use the Id since the same func

相关标签:
2条回答
  • 2020-12-07 04:56

    there is no such getElementByClassName(). Try getElementsByClassName()

    Update

    document.getElementsByClassName('..') returns a set of elements while your code is written with expectation that it'll return single element. You could change that part to

    var myContent = document.getElementsByClassName('content');
    
    var num = myContent.length;
    
    for(var x=0; x < num; x++){
        myContent[x].style.display = 'block'; //or whatever style you've in your original code 
    }
    
    0 讨论(0)
  • 2020-12-07 04:56

    It is getElementsByClassName instead of getElementByClassName. I would also recommend using jQuery or some sort of js framework.

    0 讨论(0)
提交回复
热议问题