Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  42] [ 7]  / answers: 1 / hits: 21025  / 15 Years ago, mon, november 9, 2009, 12:00:00

I have some HTML that looks like this:



<div>
<div class=value>
<a href=# class=clicker>Some Value</a>
</div>
<div class=heading>
Some Name<img src=loading.gif style=visibility:hidden>
</div>
</div>


This could repeat several times, depending on how many values and headings need to be listed. Using jQuery, I've attached a function to happen when the a.clicker is clicked. As a part of what happens, I'd like to call show() on the .heading img below it. However, I just can't get my head around how this is supposed to be selected.



$('a.clicker').live(click, function() {

// This next line, in my brain, works, but in reality it doesn't!
$('.heading img', $(this).parent().parent()).show();

// do some other AJAXy things
});


I've marked the line that I think should do it, but it's not showing the img at all. I've been poring over the documentation and soflow for a couple of hours without success.



Thanks for any assistance!


More From » jquery

 Answers
47

You just have a few things in the wrong places. Very close though.



$('a.clicker').live(click, function() {
$(this).parent().parent().find('.heading img').show();
});


This could also be solved a second way:



$('a.clicker').live(click, function() {
$(this).parent().next('.heading img').show();
});

[#98353] Thursday, November 5, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tayla

Total Points: 681
Total Questions: 102
Total Answers: 108

Location: Marshall Islands
Member since Tue, Sep 21, 2021
3 Years ago
tayla questions
Fri, Mar 5, 21, 00:00, 3 Years ago
Wed, Oct 28, 20, 00:00, 4 Years ago
Thu, Apr 9, 20, 00:00, 4 Years ago
;