我有以下代码:
$(this).children("a:eq(0)").append('<img src="'+ (arrowsvar.down[1])
+'" class="' + (arrowsvar.down[0])
+ '" style="border:0;" />'
);
现在我想删除最后添加的元素(一张图片)。 请给出建议。
作为替代方案,对于那些更喜欢编程方式和语法的人:
$('#container-element img').last().remove();
$('img:last-child', this).remove();
// get the last img element of the childs of 'this'
原问题的代码可能会生成错误(在选择器中使用“this”)。尝试以下方法:
$("#container-element img:last-child").remove()
太棒了,非常感谢Eugene,这真的帮了我很多。我必须删除一个表格,我使用了以下代码。
$("#mydivId table:last-child").remove()
$(this).children("a:eq(0)").not(':last-child').append('<img src="'+ (arrowsvar.down[1])
+'" class="' + (arrowsvar.down[0])
+ '" style="border:0;" />'
);