Get div height with plain JavaScript

前端 未结 10 936
梦毁少年i
梦毁少年i 2020-11-22 17:22

Any ideas on how to get a div\'s height without using jQuery?

I was searching Stack Overflow for this question and it seems like every answer is pointing to jQuery\'

10条回答
  •  佛祖请我去吃肉
    2020-11-22 17:58

    Here's one more alternative:

    var classElements = document.getElementsByClassName("className");
    
    function setClassHeight (classElements, desiredHeightValue) 
        {
            var arrayElements = Object.entries(classElements);
            for(var i = 0; i< arrayElements.length; i++) {
                arrayElements[i][1].style.height = desiredHeightValue;
            }
    
        }
    

提交回复
热议问题