2016-04-14 19 views
1

Belirli bir özniteliği olan bir div, iç içe geçmiş div'lar içeriyor. Bunlardan biri, belirli bir src olan bir görüntü etiketi içeriyor. Buna nasıl erişirim? kodunu takiben çalışmıyor:JQuery: Belirli bir URL ile iç içe bir Img tıklatılıyor

var tbox = $('div[role="user"]'); // These could be multiple 

tbox.click(function(){ 
    $(this).find('img[src="path/to/img.png"]').click(); 
}); 

cevap

1

Şunları kullanabilirsiniz "ends-with" selector $=:

$(function(){ 
 
     $("#box").click(function(){ 
 
      debugger; 
 
      $(this).find('a[href$="test"]').css('color','red'); 
 
     }); 
 
});
#box{ 
 
    background: #ddd; 
 
    height: 200px; 
 
    width: 200px; 
 
    padding: 20px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div id='box'> 
 
    <a href='#test'>TEST</a> 
 
    <a href='#test'>NOT TEST</a> 
 
    <a href='#not'>TEST</a> 
 
    <a href='#not'>NOT TEST</a> 
 
</div>

: Bu bir örnek aşağıda gösterilmiştir görebilirsiniz

$(this).find('img[src$="path/to/img.png"]').click(); 

İlgili konular