[英]Jquery button triggers on any click event on whole page
This is probably a very simple question.这可能是一个非常简单的问题。
here's my code.这是我的代码。
$( document.body ).click(function () {
if ( $( ".more" ).first().is( ":hidden" ) ) {
$( ".compleatelist" ).slideDown( 6000 );
} else {
$( ".compleatelist" ).hide();
}
});
However, the button triggers when I click on ANY click event in the whole page not my ".more" button?但是,当我点击整个页面中的任何点击事件而不是我的“.more”按钮时,按钮会触发?
What am I missing here?我在这里缺少什么?
$( document.body ).click() <-- This means you are firing click on all clicks on the document body
You probably want你可能想要
$(".more").click(function(e){
// $(this) <-- this is the element you just clicked on
});
This will only fire an event when an element containing the more
class is clicked.这只会在单击包含
more
类的元素时触发事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.