First click to display a p, and then ask it to disappear when clicked again, or click on document will hide this layer, which involves bubbling problems and prevents the document from bubbling to the DOM. The code is as follows:
var $el = $(".search-more, .article-query-list li"); $el.click(function(e){ e.stopPropagation(); $(this).toggleClass('active'); }); $(document).on('click',function(e){ if(($(e.target) != $el) && ($el.hasClass('active'))){ $el.removeClass('active'); // console.log("yes"); } });
The above is the detailed content of jQuery method to hide div. For more information, please follow other related articles on the PHP Chinese website!