javascript - Remove a div with it's child elements in jquery -
i have method need remove current div it's element on clink. it's not doing anything. have searched goggle , applied various thing no result. can please me on please?!!! here code below ::
my div elements , remove link stated >>>
<div class="col-xs-4 pnorppl" id="ppeople"> <div class="form-group"> <label for="participatedpeoplename"><g:message code="sl" default="সদস্যের নাম" /></label> <g:textfield id="participatedpeoplename" name="participatedpeoplename" class="form-control"/> <a onclick="addanothernormalpeople()">add more</a> || <a onclick="removethismember()">remove</a> </div> </div>
my remove function >>>
function removethismember(){ $(this).closest('.pnorppl').remove(); }
the context of this
not carry through when use on*
attributes. instead need pass it:
<a onclick="removethismember(this)">remove</a>
function removethismember(el) { $(el).closest('.pnorppl').remove(); }
or can attach event via jquery:
<a href="#" class="remove-link">remove</a>
$('.pnorppl').on('click', '.remove-link', function(e) { e.preventdefault(); $(this).closest('.pnotppl').remove(); });
Comments
Post a Comment