remove last append element jquery

后端 未结 5 935
慢半拍i
慢半拍i 2020-12-23 17:50

I have the following code:

$(this).children(\"a:eq(0)\").append(\'

        
相关标签:
5条回答
  • 2020-12-23 18:13

    As an alternative, for those who likes more programmatic ways and syntax:

    $('#container-element img').last().remove();
    
    0 讨论(0)
  • 2020-12-23 18:13

    try this. Just added .not(':last-child') which excludes the last element in your collection. So you don't have to remove it.

    $(this).children("a:eq(0)").not(':last-child').append('<img src="'+ (arrowsvar.down[1]) 
        +'" class="' + (arrowsvar.down[0])
        + '" style="border:0;" />'
    );
    
    0 讨论(0)
  • 2020-12-23 18:16

    amazing, thank you very much eugene, that really helped me. I had to remove a table, i used the following code.

    $("#mydivId table:last-child").remove()
    
    0 讨论(0)
  • 2020-12-23 18:23

    The code from the original question may generate errors (using "this" with the selector). Try the following approach:

    $("#container-element img:last-child").remove()
    
    0 讨论(0)
  • 2020-12-23 18:30

    You can use the :last-child selector to find the last appended element, then you can remove it:

    $('img:last-child', this).remove();
    // get the last img element of the childs of 'this'
    
    0 讨论(0)
提交回复
热议问题