user168507
user168507

Reputation: 881

jquery find element

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

Upvotes: 0

Views: 7258

Answers (4)

James Allardice
James Allardice

Reputation: 165941

Use this function:

$(".checkVacancy a").click(function() {
   var theImage = $(this).find(".imgBtn"); 
});

Upvotes: 1

Steve Claridge
Steve Claridge

Reputation: 11080

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');

Upvotes: 0

JohnP
JohnP

Reputation: 50009

What you want is

var imgBtn = $(this).find('.imgBtn');

This will find the image within the link that you clicked.

Upvotes: 4

Giann
Giann

Reputation: 3192

This will get you all imgBtn within a within checkVacancy divs:

$('div.checkVacancy a .imgBtn')

Upvotes: 0

Related Questions