Change height on div with javascript

前端 未结 4 1104
遥遥无期
遥遥无期 2021-01-29 15:28

I want to set the height on a div when the div is more than 100px in height.

For example, when the content of the div makes the div\'s height fill more than 100px, I wan

4条回答
  •  温柔的废话
    2021-01-29 16:31

    One way you can do this is to make sure there is no "height" attribute in the elements CSS (inline styling is fine). Then, when the content is changed call this function:

    if ($('#myDiv').height() > 100) {
        // Div is larger than 100px so increase it to 200px
        $('#myDiv').css('height', '200px');
    }
    

提交回复
热议问题