Answer the question
In order to leave comments, you need to log in
How to make a block close on button click?
Kind.
Please tell me
how to make such a block on top so that it disappears when clicked?
Preferably Jquery, I think something like display: block, when you click, a class is given and it is display: none?
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
The code in Jquery
$(document).ready(function(){
$('body').on('click', '.close-me-button', function(){
$(this).hide();
});
});
<div class="close-me-button">Я блок, кликни по мне и я исчезну!</div>
$('.close-btn').on('click', function(){
$(this).closest('.hideme').hide();
})
In my opinion, it's best this way, a separate class for the hide button and a separate class for the block that will be hidden, here is an example: https://jsfiddle.net/ngdxcob8/
And it will work at any level of nesting.
If the html has something like this:
<div>
Это блок, который должен скрываться
<div class="hidder">X</div>
</div>
$(document).ready(function() {
$(".hidder").click(function() {
$(this).parrent().hide();
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question