开发者

Reference anchor inside a td on click of this

here is what i have:

<td class="player"><a class="link" data-display="0" data-id="1" data-workdir="4">Image.jpg</a></td>

Ok, and here is my jQuery:

$(".player").click(function(){
alert($(this + " a.link").attr("data-display"));
// Código para llamar al reproductor indicado
$.post(
    "php/player.php",
    { display : $(this).attr("data-display"), id : $(this).attr("data-id"), workdir : $(this).attr("data-id") },
    function(data){
        alert(data);
    }
);

});

What i'm trying to do is to pass the a开发者_StackOverflow社区ttributes that are inside the anchor when a person clicks the td, it would be also great to do the same when the person clicks the tr outside the td, but the td will do. (The alert is just an experiment to see if i can reference the inside link, but it didn't work). I also know that i can put the attributes inside the td and make my life easier, but i would also like to learn.


If i get it right, this is what you need:

alert($("a.link", this).attr("data-display"));


You can use .find() to get a descendant element (or .children() as well, in this case), like this:

$(this).find("a.link").attr("data-display")

You can give it a try here, for other relative methods, you want the tree traversal section of the jQuery API.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜