JavaScript jQuery - Removing a cloned element jquery remove cloned element,jquery remove cloned row,jquery remove

I am trying to make a web form which has the option to add and remove a new element. I can get this working as buttons outside of the source or cloned elements, but I am having a problem getting a 'Remove' button to work within a cloned element.

The HTML code is:

<table>
    <tr><td class="associate_column_left">
        Bursary award rates:</td><td class="associate_column_right">
        <div class="clone">£ <input type="text" name="AMOUNT" value="100" class="cl"><a target='_blank' href="#" class="remove_trigger">Delete amount</a></div>
        <div class="placer"></div>
        <p><a target='_blank' href="#" class="clone_trigger">Add another bursary award amount</a> &nbsp; <a target='_blank' href="#" class="remove_trigger">Remove last bursary award amount</a></p>
    </td></tr>
</table>

And the current jQuery is:

// Start code for duplicating a div box
$(document).ready(function(){
    $(".clone_trigger").click(function () {
        $('.clone').first().clone().insertBefore(".placer");
        $('input.cl:last').val('');
        event.preventDefault();
    });
});
// End code for duplicating a div box

// Start code for removing an already duplicated div box
$(document).ready(function(){
    $(".remove_trigger").click(function () {
        if ($(".clone").length != 1) {
            $(".clone:last").remove();
        }
        //$('.clone:last').not('.clone:first').remove();
        event.preventDefault();
    });
});
// End code for removing an already duplicated div box

This is a working jfiddle at http://jsfiddle.net/dalepotter/fr8p8/1/

The 'Add another bursary award amount' and 'Remove last bursary award amount' links at the bottom of the table work fine, but not the 'Delete amount' - which is meant to remove the row that it is contained within.

Something seems to be wrong though... If anyone has any advice please do let me know - it's driving me a bit crazy!

Many thanks for any time that you can give...

Answer:1

The problem is that the .remove_trigger-elements are not present when you attach the click eventhandler, try changing this line

$(".remove_trigger").click(function () {

to this

$("table").on("click", ".remove_trigger", function () {
Answer:2

I've been experimenting and it seems like only form elements and the window object can trigger the keypress event. I checked MDN documentation, and also the spec, but couldn't find anywhere that ...

I've been experimenting and it seems like only form elements and the window object can trigger the keypress event. I checked MDN documentation, and also the spec, but couldn't find anywhere that ...

When defining a class in Javascript, how can I call one method from another one? exports.myClass = function () { this.init = function() { myInternalMethod(); } this....

When defining a class in Javascript, how can I call one method from another one? exports.myClass = function () { this.init = function() { myInternalMethod(); } this....

  1. calling method from another class
  2. calling method from another class c#
  3. calling method from another class python
  4. calling method from different class java
  5. calling method from main java
  6. calling method from parent class python
  7. calling method from same class java
  8. calling method from superclass java
  9. calling method from class python
  10. calling method from constructor java
  11. calling method from abstract class java
  12. calling method from parent class java
  13. calling method from another component angular
  14. calling method from this
  15. call method from another activity android
  16. call method from another class react
  17. call method from another script unity
  18. call method from activity to fragment
  19. call method from another controller laravel
  20. call method from another component vue

I'm wanting to use jQuery to dynamically modify the background color of a <div>, based on its CSS property, width value. The usage is for some form of color-coded meter, which indicates how ...

I'm wanting to use jQuery to dynamically modify the background color of a <div>, based on its CSS property, width value. The usage is for some form of color-coded meter, which indicates how ...

  1. change background color in photoshop
  2. change background color google docs
  3. change background color html
  4. change background color instagram story
  5. change background color illustrator
  6. change background color in word
  7. change background color css
  8. change background color indesign
  9. change background color on iphone
  10. change background color javascript
  11. change background color in outlook
  12. change background color using css mdn
  13. change background color online
  14. change background color after effects
  15. change background color of picture
  16. change background color excel
  17. change background color gimp
  18. change background color premiere
  19. change background color instagram story video
  20. change background color in pages

I need to get the window inner height of the window, taking into account the x-scroll bar. but it seems window.innerHeight returns the same height regardless of whether or not the x-scroll bar is ...

I need to get the window inner height of the window, taking into account the x-scroll bar. but it seems window.innerHeight returns the same height regardless of whether or not the x-scroll bar is ...

  1. window innerheight vs outerheight
  2. window innerheight css
  3. window innerheight mobile
  4. window innerheight iframe
  5. window innerheight jquery
  6. window innerheight javascript
  7. window.innerheight
  8. window.innerheight vs document.documentelement.clientheight
  9. window.innerheight vs screen.height
  10. window.innerheight not working
  11. window.innerheight vs document.body.clientheight
  12. window.innerheight js
  13. window.innerheight react
  14. window.innerheight safari mobile
  15. window.innerheight undefined
  16. window.innerheight document.documentelement.clientheight
  17. window.innerheight scrollbar
  18. window.innerheight browser support
  19. window.innerheight vs clientheight
  20. window.innerheight too big