Prince Prince - 4 months ago 21
Javascript Question

Find and fadeout an element in jQuery

I am working on a project and I would like to use Jquery to

fadeOut
, the link having a
data-code
equal to 1



<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>


I was trying to do it but I got stuck here:



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

itemsInBox.fadeOut();

Answer

The proper way will be to combine everything in one selector:

$(".contentwrapper .content .removebutton[data-code='1']").fadeOut();

DOCS: http://api.jquery.com/attribute-equals-selector/