jQuery: Toggle 'addclass' on Click and Remove on Outside Click
$(document).on('click', '.xdi', function(event) { if (!$(event.target).closest('.xdi').length) { $('.addclass').removeClass('addclass'); } }); $(document).on('click', function(event) { if (!$(event.target).closest('.xdi').length) { $('.addclass').removeClass('addclass'); } }); With this code, when you click on any element inside the document, it checks if the clicked element or its ancestors have the class "xdi". If not, it removes the "addclass" from elements with the class "addclass".
原文地址: https://www.cveoy.top/t/topic/qosD 著作权归作者所有。请勿转载和采集!