views:

45

answers:

2

How can I select the src attr from the zoom span?

$(".gallery span.zoom").click(function() {
        // var imgPath = $(this).parent()......attr("src");
        // alert(imgPath);
    return false;
});

<ul class="gallery">
    <li id="li-1">
        <img src="002171/tn/001.jpg" alt="image" />
        <span class="delete"></span>
        <span class="zoom"></span>
        <em>hello world</em>
    </li>
</ul>
+3  A: 

try:

$(".gallery span.zoom").click(function() {
        var imgPath = $(this).siblings('img').attr("src");
        alert(imgPath);
    return false;
});
Reigel
allright Reigel!
FFish
+1  A: 
$(".gallery span.zoom").click(function() {
    alert($(this).parent().find('img').attr('src'));
    return false;
});
Salman A
why go to the `parent()` ? when you can go directly to it as a sibling?
Reigel
He wrote `$(this).parent()......attr("src")`, I filled in the blank!
Salman A
that's what he was guessing... and he might not ask if he knew it... So, might as well give the OP the best answer you can... ;)
Reigel