0

私は次のようなhtmlスキームを持っています

<li>Some text <a href='#' class='click'>Remove</a> <input type='hidden' ></li>

そして私はOnClick機能を持っています

$(".click").click(function() {
    // i need to select 'li' and then delete it
    // i have this code, but its not working
    $(this).prev('li').remove();
    return false;
});

以前のhtmlタグonClickを選択するにはどうすればよいですか?

4

2 に答える 2

6

li前の要素ではなく、親です。

$(".click").click(function () {
    $(this).parent().remove();
    return false;
});
于 2012-07-21T13:46:39.157 に答える
3

.prevは兄弟用で、あなたの場合liは親なので、を使用できます.closest

$(".click").click(function () {
        $(this).closest('li').remove();
        return false;
});
于 2012-07-21T13:47:03.097 に答える