2013-11-21 64 views
1

我想使用jQuery将所有div标记的高度更改为特定的class。 我已经成功地使用CSS设置高度,但我想从jQuery中更改它。在jQuery中更改div的高度

我曾尝试下面的代码:

$('.slide-container').css({ "height": 200 + "px !important" }); 
    $('.slide-container').height(200); 
    $('.slide-container').css({ "height": 200 + "px" }); 

这是将原来的高度的CSS。

.slide-container {  height:300px !important; } 

Here is a JSFiddle of my attempts.

+0

为什么你的问题的标题有'C#'呢? – P5Coder

+1

为什么在你的类声明中设置'!important'?你应该永远不要使用它,除非你知道你在做什么...... – nietonfir

+0

@ user1167870你提供的答案有帮助你吗? – Haohmaru

回答

0
<div class="slide-container"> 
    apply height to a div tag ,that div is generating from 
    jquery with some class, when height comes from database! 
</div> 



<script type="text/javascript"> 

    var newHeight = yourHeightFromDB; 
    $(function() { 
     $('.slide-container').height(newHeight); 
    }); 

</script> 
0

变化在CSS线

height: 300px !important;

height: 300px;

该声明基本上不允许您动态设置高度。 Your Jquery code is working fine.

人能为这个代码以及

$(document).ready(function() { 

     $('.slide-container').height(500); 
    });