Enot
Enot

Reputation: 830

Javascript not loaded when ajax content is loaded

I have an issue that is relative with dynamically loaded content, having a sidebar which has links and loads pages in this way; the problem is relative that javascript is not working when pages are loaded, I used $document(ready) for this target but it is not working at all, any hint for this?

Upvotes: 0

Views: 70

Answers (1)

michael
michael

Reputation: 4483

I would assume you're binding events in this way...

$('a').click(function () {});

And the expecting this event to fire when an anchor is clicked within the dynamic content?

Try binding the event to an element that doesn't change when a page is loaded in eg.

$('body').on('click', 'a', function () {});

What happens is that the event is actually bound to the body, when the click event fires on the anchor it bubbles up to the body which then delegates it back to the anchor

Upvotes: 2

Related Questions