开发者

jQuery: Using Variables in Selectors

开发者 https://www.devze.com 2022-12-13 10:11 出处:网络
Every searches I made only included solutions for variables like this: $(\'#div\'+ id) I need to delete a row.

Every searches I made only included solutions for variables like this: $('#div'+ id)

I need to delete a row.

var row = $(this).parent().parent().parent().find('tr#' + id).html();

I'd like to use the "row" name instead of "$(this)..开发者_如何学JAVA.remove();"


like

$('tr[name='+rowname+']').remove()


use .closest, it is safer than all those chained parent calls in case you change the markup which will break the code.

var row = $(this).closest('tr');
row.remove()


Just populate the row var with a reference to the row.

var row = $(this).parent().parent().parent().find('tr#' + id);
var html = $(row).html();
$(row).remove();
0

精彩评论

暂无评论...
验证码 换一张
取 消