为什么$(this.attr(“";id";)在使用javascript更改旧属性后获取它

为什么$(this.attr(“";id";)在使用javascript更改旧属性后获取它,javascript,attributes,attr,Javascript,Attributes,Attr,我有一个奇怪的问题,所以在删除一行后,我更改了所有表行的id。 以下是我代码的一部分: $(document).on("click",".fa-trash-alt",function(){ console.log($(this).attr("id")) let index = parseInt($(this).attr("id")) globalFunctions.removeFromChoo

我有一个奇怪的问题,所以在删除一行后,我更改了所有表行的id
以下是我代码的一部分:

$(document).on("click",".fa-trash-alt",function(){
    console.log($(this).attr("id"))
    let index = parseInt($(this).attr("id"))
    globalFunctions.removeFromChoosedList(index)
    $('tr#'+index).remove()
    let rows = $(".choosed-table-data tr")

   $.each(rows,function(index,value){
     $(value).attr("id",index)
   })
  })

问题是,在执行此操作后,当我单击一个应该有新id的行时,旧id将显示在控制台.log($(this).attr(“id”)中,尽管在inspector上更改了id,但很难给出示例,因为没有HTML将js代码与之关联。如果您想要更相关的示例,请编辑问题以包含html

$(“.clicked elm”)。单击((e)=>{
//删除单击的元素
e、 target.remove();
//如果要删除子项,请执行以下操作:
e、 target.children.forEach(elm=>elm.remove());
//不确定选择的数据表是什么,
//但是这个例子应该改变这个类中每个元素的id,
//除非$()只选择第一个元素。
//如果是,请将其更改为$$(),并应选择所有匹配项。
$(“.choosed表数据tr”).forEach((elm,i)=>$(elm.attr(“id”,i));
});
@Invizi
感谢您的澄清显然您的说明是正确的,我认为我的问题很清楚,但事实并非如此。 不管怎样,我找到了我犯错误的地方,正如您所看到的,我想获取行的“id”(tr),它是按钮(“.trash alt”)的父级,但我所做的是:
$(this.attr(“id”)
我应该在哪里执行此操作:
$(this).parentElement.parentElement.id
在我到达目的地之前,从父母那里搬走 平均值:=>=> 我觉得我是个白痴 最后是我的固定代码

  $(document).on("click",".fa-trash-alt",function(e){
    let parent = e.target.parentElement.parentElement
    let index = parent.id
    globalFunctions.removeFromChoosedList(index)
    parent.remove()
    let rows = $(".choosed-table-data tr")

   $.each(rows,function(index,value){
     $(value).attr("id",index)
   })
  })

谢谢你的澄清显然你的话是对的,我以为我的问题是对的,但事实并非如此。