Wizard
Wizard

Reputation: 22113

Rather than locate e.target's ancestor by multiple parent traversing

I'd like to hide the ancestor of the event.target,
to achieve this, I find the element to be hidden in multiple parent traverse

$(document).ready(function(){
    $(".editCommentLink").on("click", function (e) {
        e.preventDefault();
        $comment = $(e.target).parent()//<a>
                              .parent()//post-menu
                              .parent()//additional-info
                              .parent()//col-md-12
                              .parent()//row
                              .parent()//comment-right
                              ;
        $comment.hide();
    });
})

the comments are of a for loop

{% for comment in page.object_list %}
    <div class="comment"> 
       <div class="row">
            ...
            <a class="editCommentLink" href="#">
<span class="glyphicon glyphicon-edit" aria-hidden="true">edit </span></a> 

It seems clumsy, how to solve such a problem in a straightforward way?

Upvotes: 0

Views: 14

Answers (1)

Kosh
Kosh

Reputation: 18423

You might use $(e.target).closest('.comment')

Upvotes: 1

Related Questions