How to remove the element that is the DOM(detach)?

You need to remove items which were under the "detach". The point is that everything works except for the removal because it does not find these elements(there is no reference in the code because it looks for very different(I mean styep_id)). How to do it right?

// We gonna use a flag to see if the function got executed
let est_wont_show_execution_flag = false;

est_wont_show function() {
 var HideThis, estpgt_id;

 estpgt_id = $(this).attr("estpgt_id");

 HideThis = $("#estpgt_" + estpgt_id).detach();
 HideThis = $("#estpt_tr_for_" + estpgt_id).detach();

 if (document.body.getElementsByTagName(HideThis)) 
{
 //Check if element is detached
 console.log("Element is in the DOM");
}

 est_wont_show_execution_flag = true;
}

//Function is used by a button
TEST_ALERT function() {
 // Did est_wont_show has been executed ?
 if (est_wont_show_execution_flag) {
 var estpt_tr_jqobj, estpt_action_links_td_jqobj, styep_id, authenticity_token, request_url, stya_id;

//DELETION PART
 styep_id = $(this).attr("styep_id");

 // Remove from DOM
 if (styep_id == "") {
 estpt_action_links_td_jqobj = $(this).parent();
 estpt_tr_jqobj = estpt_action_links_td_jqobj.parent();
 stya_id = $("td.service-type-est-position-estimate-position-type-name>input.stya-id-for-styep", estpt_tr_jqobj).val();
estpt_tr_jqobj.remove();
show_stya_delete_link_if_possible(stya_id);
remove_estpgt_if_has_no_estpt($(this).attr("estpgt_id"));
}
 else {
 // Remove from DB
 authenticity_token = $("#authenticity_token").val();
 request_url = "/service_type_est_positions/" + styep_id + "/destroy_from_service_type_config";

 $.post(request_url, { authenticity_token: authenticity_token}, process_service_type_est_position_delete, "json");

}
 console.log('TEST_ALERT : est_wont_show has been executed');
return;
}

 console.log('TEST_ALERT : est_wont_show hasn\'t been executed');
}
June 5th 19 at 21:34

Find more questions by tags JavaScript