1

I am using $.get() to load new content into a div. The content includes a list, each row having a title and a hidden description.

I have a separate jquery call that is meant to toggle the hidden div for each row when clicking on the title, which works fine when the data already exists (default content loaded with the page), but when it's dynamically replaced with a $.get() call, the divs then seem to become invisible to the command..

Any ideas? Do I need to somehow get javascript to refresh it's version of the DOM? TY

3
  • 2
    Can you post your toggle code? Commented Jan 31, 2011 at 21:09
  • how are you wiring the toggle? if you are loading dynamically then your bind should be .live() instead of .bind(). post your code for better help. Commented Jan 31, 2011 at 21:11
  • I was simply using the click function: $(".show_link").click(function (e) {}); (which isn't being called- tested with a basic alert();) Commented Jan 31, 2011 at 21:13

2 Answers 2

3

Try this instead. This will bind elements that are inserted after the page loads:

$(".show_link").live('click', function (e) {});

The way you are binding the command it only happens when the page loads, so it will only bind those elements that match the selector at the time the page loads. Since you are inserting the markup after the page loads, jquery does not know those elements exist and therefore not wired to your function. Like I said above, try using .live() instead.

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

Comments

0

The DOM should update automatically. Are you sure the content you're loading has the appropriate Ids?

Try manually browsing to the URL used in the AJAX call and compare what you get with what's originally in the page. It's also possible you're retrieving spurious tags (html, body, etc) which may interfere with your JQuery selector

Comments

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.