Advertisement
Naralex

04. Selectable-Towns

Jul 13th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function attachEvents() {
  2.     $('#items li').on('click', arrayManipulation);
  3.     let arr = [];
  4.     function arrayManipulation() {
  5.         if ($(this).attr('data-selected') === 'true')
  6.         {
  7.             $(this).attr('data-selected', 'false').css('background', '#808080');
  8.             arr.splice(arr.indexOf($(this)["0"].textContent),1);}
  9.         else
  10.         {
  11.             $(this).attr('data-selected', 'true').css('background', '#DDD');
  12.             arr.push($(this)["0"].textContent);
  13.         }
  14.     }
  15.     $('#showTownsButton').on('click', printResults);
  16.     function printResults() {$('#selectedTowns')["0"].textContent = arr.join(', ');}
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement