Home  >  Article  >  Web Front-end  >  jQuery method to hide div

jQuery method to hide div

零下一度
零下一度Original
2017-06-17 17:43:111420browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn