Unable to access dom element using identifier after successfully cloning and appending it

StackOverflow https://stackoverflow.com/questions/5419216

  •  29-10-2019
  •  | 
  •  

Question

I prepare a clone of a template div, assign it a dynamic ID and append it to DOM, like this:-

var chat_window_clone_obj = $('div#chat_window_template').clone();

cloned_element_id = 'chat_window'+dom_id_separator+session_id;
$(chat_window_clone_obj).attr('id',cloned_element_id);
$(chat_window_clone_obj).appendTo("div#chat_windows_holder");

But, after that I am not able access the cloned element using its ID (checked in firefox, I am sure this will be the same in all browsers):-

$('div#chat_windows_holder').length // comes 0
$('div#chat_windows_holder').removeClass("hidden"); //does not work

I am however able to access like this:-

$(chat_window_clone_obj).length // works
$(chat_window_clone_obj).removeClass("hidden"); //works

What am I missing here? I can see the element appended correctly with the required ID in firefox's HTML tab.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top