JavaScript Cloning closest table row

I recently asked this question

Since then I have discovered that what I wanted to do wont work. This is because the table is generated by a for loop, with their id incrementing each time. As such, I needed to amend things so that it would add rows for the table it is supposed too. I have updated my fiddle to show an example with two table JSFiddle

Essentially, I now do this

$(function() {
    $(".addCF").click(function(){
       var clone = $(this).closest('tr').clone(true).insertAfter($(this).closest('tr'));
    });
    $("#customFields").on('click','.remCF',function(){
        $(this).parent().parent().remove();
    });
});

I can get the name and label of the cloned rows done myself using the previous examples. My main problem is that I do not want to clone the whole row. At the moment, it is cloning this

<tr>
    <td><label class="subjectline" for="User1">User NOC M1</label></td>
    <td id="slLabel">SL_A</td>
    <td id="slInput"><input type="text" name="slOptions[User][NOC M1]" class="form-control" id="User1"></td>
    <td><a class="addCF" target='_blank' href="javascript:void(0);">+ additional user</a></td>
</tr> 

I need it to clone this but make the first td empty. Additionally, like the initial question, the last td should be a close button

<a target='_blank' href="javascript:void(0);" class="remCF">Remove</a>

Is it possible to do this?

Thanks

Answer:1

You need to change your Cloned TR's html:

HTML:

<table id="customFields1" class="table table-bordered table-hover additionalMargin alignment">
    <thead>
    <tr>
        <th colspan="2"></th>
        <th>Some Title</th>
    </tr>
    </thead>
    <tbody>
        <tr>
            <td><label class="subjectline" for="User1">User NOC M1</label></td>
            <td id="slLabel">SL_A</td>
            <td id="slInput"><input type="text" name="slOptions[User][NOC M1]" class="form-control" id="User1"></td>
            <td><a class="addCF" target='_blank' href="javascript:void(0);">+ additional user</a></td>
        </tr> 

    </tbody>
</table>

<table id="customFields2" class="table table-bordered table-hover additionalMargin alignment">
    <thead>
    <tr>
        <th colspan="2"></th>
        <th>Some Title</th>
    </tr>
    </thead>
    <tbody>
        <tr>
            <td><label class="subjectline" for="User1">User NOC M1</label></td>
            <td id="slLabel">SL_A</td>
            <td id="slInput"><input type="text" name="slOptions[User][NOC M1]" class="form-control" id="User1"></td>
            <td><a class="addCF" target='_blank' href="javascript:void(0);">+ additional user</a></td>
        </tr> 
    </tbody>
</table>

JQUERY:

$(function() {
    $(".addCF").click(function(){
       var closest_tr =$(this).closest('tr').clone(true); 
       closest_tr = $(closest_tr).find("td:first").html("").parent();
       var clone = closest_tr.insertAfter( $(this).closest('tr'));
    });
    $("#customFields").on('click','.remCF',function(){
        $(this).parent().parent().remove();
    });
});

DEMO: https://jsfiddle.net/116hvkhe/

Answer:2

Here is my Angular app var filterData = angular.module('myApp',[]).controller('CallWebApi', function($scope, $http) { // Local version of the data $http.get('./events.js'). success(...

Here is my Angular app var filterData = angular.module('myApp',[]).controller('CallWebApi', function($scope, $http) { // Local version of the data $http.get('./events.js'). success(...

  1. convert this date into roman numerals
  2. convert date
  3. convert date sql
  4. convert date to string
  5. convert date to timestamp
  6. convert date to string sql
  7. convert date sql server
  8. convert date format in sql
  9. convert date to text excel
  10. convert date to roman numerals
  11. convert date to string javascript
  12. convert date to string java
  13. convert date to localdate
  14. convert date to milliseconds
  15. convert date to month in excel
  16. convert date to string python
  17. convert date sql server dd/mm/yyyy
  18. convert date format in excel
  19. convert date to timestamp javascript
  20. convert date to string php

Just wondering, is it possible to use only Javascript to hide/show elements without using "style" method? So I won't have to use any inline CSS in my HTML element. Or even, how does jQuery perform the ...

Just wondering, is it possible to use only Javascript to hide/show elements without using "style" method? So I won't have to use any inline CSS in my HTML element. Or even, how does jQuery perform the ...

  1. hide show elements javascript
  2. hide/show elements when checkbox is selected
  3. hide show elements jquery
  4. hide show elements css
  5. hide show elements html
  6. show/hide elements depending on screen size
  7. show/hide elements based on selected option
  8. show & hide elements on click
  9. show hide elements react
  10. show hide elements
  11. show hide elements react native
  12. show hide elements in react js
  13. show hide elements revit
  14. show hide elements angular
  15. show hide elements bootstrap
  16. show hide elements angular 4
  17. show hide elements dreamweaver
  18. show hide elements wordpress
  19. show hide elements responsive design
  20. show hide element angularjs

I have a well working fullcalendar script that adds css-classes to events according to data attributes via eventRender. I now need to filter these specific attributes with checkboxes, but I have no ...

I have a well working fullcalendar script that adds css-classes to events according to data attributes via eventRender. I now need to filter these specific attributes with checkboxes, but I have no ...

  1. filter fullcalendar events
  2. fullcalendar filter events example
  3. fullcalendar filter events
  4. fullcalendar events filtering

I would like to extract the GPS Exif tag from pictures using NodeJS. I got data in this format: { "gps": { "GPSTimeStamp": [2147483647, 76, 41], "GPSLongitude": [76, 41, 56.622], ...

I would like to extract the GPS Exif tag from pictures using NodeJS. I got data in this format: { "gps": { "GPSTimeStamp": [2147483647, 76, 41], "GPSLongitude": [76, 41, 56.622], ...

  1. extract data from pdf
  2. extract data from pdf to excel
  3. extract data from pdf python
  4. extract data from website
  5. extract data from excel
  6. extract data from image
  7. extract data from table matlab
  8. extract data from matlab figure
  9. extract data from excel cell
  10. extract data from website to excel
  11. extract data from pivot table
  12. extract data from website python
  13. extract data from pdf to excel free
  14. extract data from json
  15. extract data from json python
  16. extract data from xml
  17. extract data from image online
  18. extract data from eclinicalworks
  19. extract data from multiple excel files
  20. extract data from html