1

I'm trying to append a div to all dynamically added divs to my page using this code:

$('.tagged .post').append('<div class="fadeout"></div>');

but I simply cannot get it to work. So I was thinking, would it be possible to bind this outside of $(document).ready() somehow, so the code looks for all the elements that match the selector and append the "fadeout" div to them?

Willow
  • 153
  • 12

1 Answers1

1

Edit: Check out this answer: Event when element added to page

Long story short, you have two options:

  1. Continually check for the elements
  2. Use Mutation Observers

The answer I linked to above has more details.

Community
  • 1
  • 1
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
  • But what if I don't want a click event bound to the element...? How do you code it so the code watches for a dom element being added, and appends the div to it? I don't really have control over the other person's script, so I just need to detect some event that adds the element to the dom. – Willow Sep 02 '14 at 13:53
  • Sorry about that. I didn't quite understand what you were asking. I'll update my answer. – Greg Burghardt Sep 02 '14 at 13:58