for(var i=0; i<$("#apply_add_department_<%= @department.id %>").nextAll().length; i++){ var index = parseInt($($("#apply_add_department_<%= @department.id %>").nextAll()[i]).children(":first").html()); $($("#apply_add_department_<%= @department.id %>").nextAll()[i]).children(":first").html(index - 1); } $("#apply_add_department_<%= @department.id %>").remove();