开发者

How do i find a specific form using jquery and a link i clicked

I have a link an开发者_Python百科d would like to show/hide ONE form. The first line does it but it does it to ALL forms inside of the one in its own comment div. How do i select the form. the other 3 were guesses and dont work (they seem to do nothing at all). I'm thinking going up to the comment, then down to the form and use toggle on it (as the first line which works but applies to all) would do the trick. But so far it seems i get 0 elements

$('.comment .reply a').click(function() {
    $('.comment form').toggle('slow');
    //$(this).parent('.comment').children('form')[0].toggle('slow');
    //$(this).parent('.comment').find('form').toggle('slow');
    //$("form", this).toggle('slow');
});


If I understand correctly, this should do it:

$('.comment .reply a').click(function() {
    $(this).closest(".comment").find("form").toggle('slow');
});

That is to say, get the closest parent div of class .comment to the clicked anchor, and find its descendant form element.


You could try

$(this).closest('form').toggle();


Add an id to the form, and use it in the selector.


Change that to

$('.comment .reply a').click(function(event)
{
    $(event.target).parent('form').toggle('slow);
});

This will take the target of the event, find the parent form, and toggle it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜