javascript - Can't delete parent of element that had event -
i have following html:
<script type="text/x-handlebars-template" id="product-template"> <div class='product'> <button class='changeproducttype'>change</button> </div> var productview = backbone.view.extend({ el: ".container", initialize: function() { _.bindall(this, 'render','changeproducttype'); this.render(); }, events: { "click .changeproducttype": "changeproducttype" }, render: function() { var source = $('#product-template').html(); var template = handlebars.compile(source); var html = template(this.model.tojson()); this.$el.html(html); }, changeproducttype: function(ev){ var removethis = ev.target.parent(); //alert(removethis); $("#changeproducttypemodal li a").on('click', function(){ removethis.remove(); $.modal.close(); }); } }); when alert ev.target says "[object htmlbuttonelement]", good. when try remove entire .product div, doesn't work.
the error i'm getting uncaught typeerror: cannot read property 'parent' of undefined. how can remove parent element of button gets clicked?
thanks help!
try event.target.parentnode or event.target.parentelement instead of "parent()". have heard of method called "parent()" in dom api.
Comments
Post a Comment