2012-08-03 111 views
1

任何人都可以告訴我,如何從下面的div中刪除style屬性?刪除div標籤上的Style屬性

<div class="ui-state-default ui-jqgrid-hdiv" style="width: 1085px;"> 

我試過了下面,但是它並沒有刪除它。

$('.ui-state-default ui-jqgrid-hdiv').removeAttr('style') 

謝謝

回答

11

使用dotcomma加入班級選擇

Live Demo

$('.ui-state-default.ui-jqgrid-hdiv').removeAttr('style') 
+0

只是表明 - jQuery中,永遠,永遠,永遠保證在堆棧中,你認爲它的內容不知道爲什麼事情不工作了。 – Utkanos 2012-08-03 11:05:41

+0

爲什麼點?不是逗號?像這樣:$('。ui-state-default,.ui-jqgrid-hdiv')。removeAttr('style');這個例子會工作嗎? – 2012-08-03 11:07:31

+0

謝謝@barlasapaydin,我不知道逗號 – Adil 2012-08-03 11:10:05

1

或者,這可能會有幫助?..

var width = $(window).width(); //Just assuming screen width 

$('#gridId').setGriWidth(width); 
1

問題在於您的選擇器。

$('.ui-state-default ui-jqgrid-hdiv').removeAttr('style') 

必須

$('.ui-state-default.ui-jqgrid-hdiv').removeAttr('style')