What is the selector I need in order to find the class "imgBtn" inside the link that I clicked (class - "checkVacancy a")?
<div class="checkVacancy">
<a rel="123">
<img class="imgBtn" alt="" src="App_Themes/popup/bilder/btn_pruefen.png">
</a>
<div class="32531302a"></div>
</div>
<div class="checkVacancy">
<a rel="123">
<img class="imgBtn" alt="" src="App_T开发者_JS百科hemes/popup/bilder/btn_pruefen.png">
</a>
<div class="32531302b"></div>
</div>
<div class="checkVacancy">
<a rel="123">
<img class="imgBtn" alt="" src="App_Themes/popup/bilder/btn_pruefen.png">
</a>
<div class="32531302c"></div>
</div>
This is the JS I use
$(function(){
$('.checkVacancy a').click(function() {
//access only child image
$('.imgBtn').attr('src','http://www.ajaxload.info/cache/9D/E5/1C/00/00/00/1-0.gif');
});
});
example jsbin
What you want is
var imgBtn = $(this).find('.imgBtn');
This will find the image within the link that you clicked.
Use this function:
$(".checkVacancy a").click(function() {
var theImage = $(this).find(".imgBtn");
});
This will get you all imgBtn
within a
within checkVacancy
divs:
$('div.checkVacancy a .imgBtn')
If I understand your problem correctly, I think you need to add "this" to your .imgBtn selector, like this:
$('.imgBtn', this).attr('src','http://www.ajaxload.info/cache/9D/E5/1C/00/00/00/1-0.gif');
精彩评论