From 944f9c62cd9820ca0b3dae4b652222e41194756c Mon Sep 17 00:00:00 2001 From: brocktimus Date: Thu, 25 Jun 2020 19:12:46 +0800 Subject: [PATCH] Using closest instead of matches to allow clicking on sub elements like normal cocoon (#10) --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 1bdf734..c214640 100644 --- a/index.js +++ b/index.js @@ -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')); } }); @@ -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();