Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery dynamic row number not working properly

$(function() {
  function numberRows($t) {
    var c = 0;
    $t.find("tr").each(function(ind, el) {
      $(el).find("td:eq(0)").html(++c + ".");
    });
  }
  $("#add-service-button").click(function(e) {
    e.preventDefault();
    var $row = $("<tr>");
    $row.append($("<td>"));
    $row.append($("<td>").html($("#add-service").val()));
    $row.append($("<td>").html("<a class='del-service' href='#' title='Click to remove this entry'>X</a>"));
    $row.appendTo($("#service-table tbody"));
    numberRows($("#service-table"));
  });
  $("#form-entry form").submit(function(e) {
    e.preventDefault();
    $("#add-service-button").trigger("click");
  });
  $("#service-table").on("click", ".del-service", function(e) {
    e.preventDefault();
    var $row = $(this).parent().parent();
    var retResult = confirm("Are you sure you wish to remove this entry?");
    if (retResult) {
      $row.remove();
      numberRows($("#service-table"));
    }
  });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: line graph view click event 
Javascript :: sumo multiselect 
Javascript :: js vue array change position 
Javascript :: filter a table based on combibox in js 
Javascript :: react native how to pass id from list to function 
Javascript :: rxjs sequence of api calls 
Javascript :: how to delete props from url 
Javascript :: typeahead bootstrap 4 add multiple values 
Javascript :: convert binary to string javascript 
Javascript :: can we send image in json in angular 
Javascript :: Early return mdn 
Javascript :: angular key value pipe compareFn example 
Javascript :: how to remove document.getElementById("myDropdown").classList.toggle("show"); 
Javascript :: angular chart js Doughnut colors 
Javascript :: eachfeature leaflet 
Javascript :: javascript count occurrences of word in string 
Javascript :: scratch addons 
Javascript :: 100%50 JS 
Javascript :: how to call javascript function in html using thymeleaf and put argumnet as method arg 
Javascript :: in which table our redux option values are save 
Javascript :: Getting Nan when calculate two date js 
Javascript :: asciicinema 
Javascript :: halt button from submitting js 
Javascript :: how to disable time option in select jquery 
Javascript :: var fn = () = { return new Promise(r = r(5)) } 
Javascript :: advantage of array 
Javascript :: Maths help you save money 
Javascript :: handleauthenticateasync unit test 
Javascript :: select xml child element with jQuery 
Javascript :: benchmark ram usage angular 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =