G
G
GoodProject2015-11-05 07:56:41
css
GoodProject, 2015-11-05 07:56:41

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?

xETqejk.png

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
Konstantin T, 2015-11-05
@RooTooZ

The code in Jquery

$(document).ready(function(){
  $('body').on('click', '.close-me-button', function(){
    $(this).hide();
  });
});

And the HTML code
<div class="close-me-button">Я блок, кликни по мне и я исчезну!</div>

S
Stalker_RED, 2015-11-05
@Stalker_RED

$('.close-btn').on('click', function(){
    $(this).closest('.hideme').hide();
})

demo

V
Vladimir, 2015-11-05
@Vovchikvoin

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.

D
Dmitry Goyda, 2015-11-05
@Bigbad

If the html has something like this:

<div>
  Это блок, который должен скрываться
  <div class="hidder">X</div>
</div>

then you can hide through the parent
$(document).ready(function() {
  $(".hidder").click(function() {
    $(this).parrent().hide();
  });
});

When changing parent identifiers, everything will still work, which is often important, after N-years)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question