ahmed salah

ahmed salah

  • NA
  • 530
  • 142.1k

how to remove item using splice

Sep 7 2016 8:47 PM
in code below i need to using splice in place of remove function 
how to do that please
  1. <script>  
  2.        $(function () {  
  3.            $(document).on("click"".remove", function (e) {  
  4.                e.preventDefault();  
  5.                $(this).closest(".course-item").remove();  
  6.            });  
  7.            $('#AvailableCourses').change(function () {  
  8.                var val = $(this).val();  
  9.                var text = $("#AvailableCourses option:selected").text();  
  10.                var existingCourses = $("input[name='CourseIds']")  
  11.                    .map(function () { return this.value; }).get();  
  12.   
  13.                if (existingCourses.indexOf(val) === -1) {  
  14.                    // Not exist. Add new  
  15.                    var newItem = $("<div/>").addClass("course-item")  
  16.              .append(text + ' <a href="#" class="remove" data-id="' + val + '">Remove </a>');  
  17.                    newItem.append('<input type="text" name="CourseIds" value="' + val + '" />');  
  18.   
  19.                    $("#items").append(newItem);  
  20.                }  
  21.            });  
  22.        });  
  23.        </script>  
 

Answers (4)