Skip to content

Commit

Permalink
Using closest instead of matches to allow clicking on sub elements li…
Browse files Browse the repository at this point in the history
…ke normal cocoon (#10)
  • Loading branch information
brocktimus authored Jun 25, 2020
1 parent 50e38ba commit 944f9c6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ const addFieldsHandler = (btn) => {
};

document.addEventListener('click', (e) => {
if(e.target.matches('.add_fields')) {
if(e.target.closest('.add_fields')) {
e.preventDefault();
e.stopPropagation();
addFieldsHandler(e.target);
addFieldsHandler(e.target.closest('.add_fields'));
}
});

Expand Down Expand Up @@ -147,8 +147,8 @@ const removeFieldsHandler = (btn) => {

document.addEventListener('click', (e) => {
if(
e.target.matches('.remove_fields.dynamic') ||
e.target.matches('.remove_fields.existing')
e.target.closest('.remove_fields.dynamic') ||
e.target.closest('.remove_fields.existing')
) {
e.preventDefault();
e.stopPropagation();
Expand Down

0 comments on commit 944f9c6

Please sign in to comment.