2014-02-18 139 views
0

我有這樣的HTML:查找元素

<div class="section project-billing funding-type" style="display: none;" ;> 
... 
</div> 

我想選擇這個元素,我想同樣的jQuery中:

$("div[class='section project-billing funding-type']") 

其唯一

返回
[] 

不是元素。爲什麼?

我在哪裏犯錯?這是隱藏的事情嗎?

+0

你確定'$'是指jQuery嗎? –

回答

0

使用類選擇的,而不是使用屬性等於選擇器

$("div.section.project-billing.funding-type") 
0

使用CSS() jQuery中。

var checkHidden = $("div.section.project-billing.funding-type").css('display'); 

    alert(checkHidden); // returns 'none' or 'block' 

use is() in jquery. 

$("div.section.project-billing.funding-type").is(":hidden"); // return true or false 
1

合作de正在工作並返回元素,實際上jQuery的功能是返回集合,你的元素在索引1,如果jQuery將隱藏或可見,將獲得元素

Live Demo

$("div[class='section project-billing funding-type']") 

你應該在這裏,而不是使用類選擇屬性選擇的。

$("div.section.project-billing.funding-type") 
+0

請不要鼓勵在這種情況下的屬性選擇器。因爲類選擇器是性能更好的選擇。 –

+1

謝謝,我告訴過他這個問題,並且告訴他在這裏使用類選擇器。 – Adil