2013-03-14 38 views
2

我想在AJAX調用,以檢查是否響應變量的長度是更大然後1 如果這是真的,我需要這種風格添加到我的頁腳:使用jQuery添加CSS樣式沒有任何影響

success: function(response) { 
    for (var i = 0, len = response.results.length; i < len; i++) 
     { 
      if(response.results.length>1) 
      { 
       $("#footer").css("position:relative"); 
      } 
     }.... 
} 

這是我的義樣式在我的CSS文件:

#footer 
    { 
     z-index:11; 
     bottom:0; 
     position: fixed; 
     float: left; 
     width:100%; 
     height:30px; 
     background-color:black; 
    } 

我做了一些調試和一切工作,因爲它應該是工作,但我的腳部構件仍具有position:fixed

我在這裏做錯了什麼?

回答

7

嘗試:

$("#footer").css("position", "relative"); 

或:

$("#footer").css({ position: "relative" }); 

:)

+0

你的回答是正確的..謝謝 – 2013-03-14 15:00:25

2

語法的.css的()是錯誤的。它是:

$('#element').css('property', 'value'); 

看看在documentation

1
document.getElementById('footer').style.position ='relative';