2014-09-01 34 views
0

我想找到下一個匹配的類,並且使用的none一個CSS display刪除它,如果每個.col-sm-4imgsold子串在其alt屬性。如果IMG ALT標籤包括「賣」查找下一個匹配的類

的jQuery:

$('.col-sm-4').each(function() { 
    if ($("img [alt=sold]")) { 
     $(this).next('.quick-enquire a').css('display', 'none'); 
    } 
}); 

HTML:

<div class="col-sm-4 col-lg-4"> 
    <a href="http://localhost:8888/?attachment_id=420" class="thumbnail img-thumbnail" data-slb-group="28_auto_1" data-slb-active="1" data-slb-internal="420"> 
    <img width="300" height="300" src="http://localhost:8888/wp-content/uploads/2014/07/img.jpg" class="attachment-medium" alt="sold" /> 
    </a> 
    <div class="pic-options"> 
    <div class="pull-right"> 
     <span class="quick-enquire"><a href="#">Enquire about this painting</a></span> 
     <span id="isSold">sold</span> 
    </div> 
</div> 

回答

2

嘗試使用:

$('.col-sm-4').each(function() { 
    $("img[alt*='sold']") /* image having 'sold' substring in its alt attr */ 
    .parent().next()   /* go UP one level then match the next element */ 
    .find('.quick-enquire') /* find the `.quick-enquire` */ 
    .children('a')   /* select its <a> child  */ 
    .css('display', 'none'); /* .hide() the child   */ 
}); 
+1

太謝謝你了!一直在掙扎幾個小時!鍛鍊了魅力......乾杯! – user3927582 2014-09-01 21:29:02

相關問題