How do I select an element that's not yet created with Jquery?

For example, if I am going to create a facebook-like chat window and would like to manipulate it using JQuery. The problem is that the js file is loaded when the whole document is created, so when the chat window is created the computer doesn’t think I have selected it using JQuery.


Can you explain this? Where is the problem, I didn’t get it

I think the OP is asking how to attach behaviour to an element that is not present when the DOM renders.

If this is the case, then event delegation is normally the way to go:

$( "#list" ).on( "click", "li", function() {

This is basically the process of attaching the listener to a parent element that is present when the DOM renders and specifying the element you wish to target as a further parameter.

You can read more here:

1 Like

Pullo is right on. Another way to do it is:

$(document).on('click', 'test-object', function(){


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.