Home > Web Front-end > JS Tutorial > body text

jQuery method to hide div

零下一度
Release: 2017-06-17 17:43:11
Original
1527 people have browsed it

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");
}
});
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!