开发者

How to make $.get() data available to js?

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 click开发者_运维问答ing 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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜