B
B
Binarix2015-09-30 19:10:53
JavaScript
Binarix, 2015-09-30 19:10:53

How to display elements on button click with jQuery?

Hello. There are several divs, for example 6 pieces

<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>

How to make a button show multiple divs with display: none when clicked? For example, 2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2015-09-30
@Binarix

So:

$('#count-blocks').on('click', function(ev) { 
    ev.preventDefault();
    
    
    var hiddenBlocksQuantity = 0;

    $('div').each(function() {
        var isHidden = ($(this).css('display') === 'none');

        if (isHidden) {
            hiddenBlocksQuantity++;
        }
    })

    alert ('There is ' + hiddenBlocksQuantity + ' hidden blocks');
});

Demo: https://jsfiddle.net/gz5hejcu/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question