Skip to content

getAttribute call on document-fragment #2529

@trading-peter

Description

@trading-peter

Hello jquery community,

First of all:
Here's the demo

All relevant output show's up in the browser's console.
Here's a screenshot that shows the line in jQuery where the problem happens.
(You can see that elem is a document-fragment)
selection_008

Source of the demo
Can be found here

Situation
You have a delegate click event handler that targets elements by a specific attribute
$(document).on('click', '[some-attribute]', function() {...});

You have a custom element that uses html5 templates to create a simple list of items.
Each item has a button to remove the parent item itself from the list.

What happens
The click on a items button removes the element before the event reaches the jQuery event handler. At the time the event arrives, the item has been removed and placed in a document fragment. Now jQuery tests the event selector on the document fragment and that fails of course.

I guess the fix would simply be to check if the element tested on the selector actually has a attribute api?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions