2016-07-14 37 views
1

我工作的一個項目,我想使用jQuery fadeOut元素,具有鏈接data-code等於1查找和淡出jQuery中

<a class="removebutton" title="Remove" data-code="1"></a> 
<a class="removebutton" title="Remove" data-code="2"></a> 
<a class="removebutton" title="Remove" data-code="3"></a> 
<a class="removebutton" title="Remove" data-code="4"></a> 

我試圖做到這一點,但我被困在這裏:

var itemsInBox = $(".contentwrapper .content .removebutton").find("data-code"); 

itemsInBox.fadeOut(); 
+0

jQuery有方法與HTML5數據屬性的工作$( 「contentwrapper。內容.removebutton 」)的數據(「 代碼」); –

回答

4

.find("data-code")查找DOM中的<data-code>..</data-code>元件。

你可能想要一個attribute selector

var itemsInBox = $(".contentwrapper .content .removebutton[data-code]"); 
// ------------------------------------------------------^^^^^^^^^^^ 

這會做所有的人。如果你有一個具體的一個你想要的,你可以be more specific

var itemsInBox = $(".contentwrapper .content .removebutton[data-code='1']"); 
// ------------------------------------------------------^^^^^^^^^^^^^^^