0

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?

3
  • You need to show the code, and give a bit more coherent description of the problem. Commented May 15, 2013 at 10:50
  • Are you saying the Javascript itself is loaded via Ajax? Commented May 15, 2013 at 10:56
  • Do you load yr content using jQuery.load() ?? Commented May 15, 2013 at 10:58

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

That's what I looking for! Works like a charm! So there's no way to bind events to content that are not load in a dynamic content, right? Just bind to elements like body that doesn't change, good answer after all!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.