A
A
Anton Izmailov2015-11-03 10:52:35
JavaScript
Anton Izmailov, 2015-11-03 10:52:35

How to organize the correct withdrawal of tickets?

There is such a problem:
There is a list of tickets

<div class="place">1</div>
<div class="place">2</div>
<div class="place">3</div>

And there is a JS array of free places [1,3]
So here's how to assign the free class to all free places

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Zuev, 2015-11-03
@WapGeaR

var places = document.querySelectorAll('.place'),
    freePlaces = [1, 3];

[].forEach.call(places, function (place) {
    freePlaces.indexOf(+place.textContent) > -1 && place.classList.add('free');
});

Example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question