admin管理员组

文章数量:1289879

I have a polymer element which has a costum element inside it. I want to remove everything (parent and child) when I click on it.

The problem is that every time I close an instance of the parent element I get an error. I think it's related to the fact I'm removing an element that has an element inside.

How can I remove it correctly?

Here's the method code:

closeWindow: function (event, detail, sender) {
    this.firstChild.remove();
    this.remove();
}

Here's the error I'm having:

Uncaught TypeError: Cannot read property 'length' of undefined

Here's an image of the error:

I have a polymer element which has a costum element inside it. I want to remove everything (parent and child) when I click on it.

The problem is that every time I close an instance of the parent element I get an error. I think it's related to the fact I'm removing an element that has an element inside.

How can I remove it correctly?

Here's the method code:

closeWindow: function (event, detail, sender) {
    this.firstChild.remove();
    this.remove();
}

Here's the error I'm having:

Uncaught TypeError: Cannot read property 'length' of undefined

Here's an image of the error:

Share Improve this question edited May 17, 2014 at 20:01 APerson 8,4228 gold badges38 silver badges49 bronze badges asked May 17, 2014 at 19:54 iroyoiroyo 7637 silver badges25 bronze badges 4
  • Can you create a jsfiddle that shows off this behavior? – Peter Burns Commented May 17, 2014 at 23:36
  • What's wrong with just this.remove()? – ebidel Commented May 19, 2014 at 23:00
  • Good news!! with the new release (0.2.4) this error seems to be solved – iroyo Commented May 23, 2014 at 14:43
  • 1 Interesting, I have a same problem. It doesn't seem to me that it has been resolved. – Aero Wang Commented Feb 27, 2015 at 15:23
Add a ment  | 

2 Answers 2

Reset to default 7

This issue was fixed a few releases ago and should also work fine in Polymer 0.3.x onwards. If you run into any further issues with this.remove() within the scope of an element, please file an issue.

On polymer 1.5.0+ you do event.target.remove()

本文标签: javascriptPolymer Correctly remove polymer element whith elements inside itStack Overflow