Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function attachEvents() {
- $('#items li').on('click', arrayManipulation);
- let arr = [];
- function arrayManipulation() {
- if ($(this).attr('data-selected') === 'true')
- {
- $(this).attr('data-selected', 'false').css('background', '#808080');
- arr.splice(arr.indexOf($(this)["0"].textContent),1);}
- else
- {
- $(this).attr('data-selected', 'true').css('background', '#DDD');
- arr.push($(this)["0"].textContent);
- }
- }
- $('#showTownsButton').on('click', printResults);
- function printResults() {$('#selectedTowns')["0"].textContent = arr.join(', ');}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement