How to make a closing accordion when you click outside of it?

强颜欢笑 提交于 2019-12-13 05:17:34

问题


Please help me! I create a simple accordion and I'm trying to make it close when you click anywhere on the page, except for accordions content.

See JSFiddle: jsfiddle.net/2DaR6/201/


回答1:


Just check to see if the clicked element was in the accordian or not

$(document).click(function(e) {
    if (!$( "#acc" ).is(e.target) && !$( "#acc" ).has(e.target).length) {
        $('#acc').accordion('activate', -1);
    }
});

http://jsfiddle.net/2DaR6/202/



来源:https://stackoverflow.com/questions/18421214/how-to-make-a-closing-accordion-when-you-click-outside-of-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!