2014-04-07 66 views
0

我仍然有一些問題。在我的HTML代碼中,我設置了一個DIV隱藏。刪除DOM和jQuery中的屬性

<div id="personalProfileWrap" style="visibility: hidden"> 

我在java腳本中改變了幾次我的方法,它可以被刪除這個歸因。這些是我已經嘗試過的功能:

var div = document.getElementById("personalProfileWrap"); 
div.setAttribute("style", ""); 
//$("#personalProfileWrap").removeAttr("style"); 

我也用Dom getElement測試過,仍然不起作用。不知道問題出在哪裏。

請注意。

+0

它的工作原理在這裏看到:http://jsfiddle.net/ZzEjL/ – smistry

+0

'$(「#personalProfileWrap 「).removeAttr(」style「);'應該工作 - http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_html_removeattr – Nick

+0

[jsFiddle demo](http://jsfiddle.net/7aNPa/2 /)評論@ user3388636 ... –

回答

3

這是一個簡單document.getElementById("personalProfileWrap").removeAttribute("style");

你甚至不需要jQuery的它。如果您只想刪除一個或兩個項目,則必須先執行.getAttribute("style"),然後解析所設置的樣式(分號分隔符),刪除所需的項目,然後執行.setAttribute("style", newStyleString)

0

以下爲我工作的jQuery:

$("#personalProfileWrap").css("visibility", "inherit"); 

這裏我(短)jsFiddle demo