0

I am having a bit of an issue. I want to bind elements (in Jquery) to an event Listener. I would normally do it in the $(document).ready() but these elements are not created yet in the body, so they are not binded with the event listeners. I would like to know if there is a way of doing this so I don't have to bind the elements every time I create a new element.

The elements are created like this : $("#theDiv").html(functionReturningHTMLString())

Thank you all

Biratus
  • 23
  • 1
  • 1
  • 8
  • 1
    [So much information available](https://www.google.com/search?q=site%3Astackoverflow.com+jquery+bind+events+after+load&gws_rd=ssl) if you care to search for it. –  Nov 24 '15 at 18:49

1 Answers1

0

You can bind the events via $.on even if the elements are not in the DOM yet.

I'm assuming you were trying to use $.click which can only be used for elements that already exist in the DOM.

Lucas Pottersky
  • 1,844
  • 6
  • 22
  • 38