Advertisement
arcsales

Selectable Towns

Jul 15th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.73 KB | None | 0 0
  1. function attachEvents() {
  2.     let content = [];
  3.     let liItems = $('#items li').toArray();
  4.     let btnClicked = $('#showTownsButton');
  5.     $(liItems).on('click', selected);
  6.  
  7.     function selected() {
  8.         for (town of liItems) {
  9.             if ($(this).attr('data-selected') === "true") {
  10.                 $(this).attr('data-selected', false)
  11.                     .removeAttr('id', 'selectedTowns')
  12.                     .css('background-color', '')
  13.                     .map(x => content.pop(x.textContent));
  14.             } else {
  15.                 $(this).attr('data-selected', true)
  16.                     .attr('id', 'selectedTowns')
  17.                     .css('background-color', '#DDD')
  18.                     .map(x => content.push(x.textContent));
  19.             }
  20.         }
  21.     }
  22.     $(btnClicked).on('click', btnClickedF);
  23.  
  24.     function btnClickedF() {
  25.         $('#selectedTowns').text(content.join(', '));
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement