Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function attachEvents() {
- let content = [];
- let liItems = $('#items li').toArray();
- let btnClicked = $('#showTownsButton');
- $(liItems).on('click', selected);
- function selected() {
- for (town of liItems) {
- if ($(this).attr('data-selected') === "true") {
- $(this).attr('data-selected', false)
- .removeAttr('id', 'selectedTowns')
- .css('background-color', '')
- .map(x => content.pop(x.textContent));
- } else {
- $(this).attr('data-selected', true)
- .attr('id', 'selectedTowns')
- .css('background-color', '#DDD')
- .map(x => content.push(x.textContent));
- }
- }
- }
- $(btnClicked).on('click', btnClickedF);
- function btnClickedF() {
- $('#selectedTowns').text(content.join(', '));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement