Advertisement
YavorJS

01. Delete Towns By Name

Jul 18th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. function attachEvents() {
  2. let input = '';
  3.  
  4. $('#btnDelete').click(function () {
  5. let message = '';
  6. input = $('#townName').val();
  7. let towns = $('#towns option');
  8. for (let town of towns) {
  9. if (town.text === input) {
  10. $(`#towns option:contains(${input})`).remove();
  11. message = `${input} deleted.`;
  12. break;
  13. }
  14. message = `${input} not found.`;
  15.  
  16. }
  17. $('#result').text(message);
  18. $('#townName').val('');
  19. });
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement