开发者

Automatically load content into a created div in jquery

I'm looking for a way to have jquery automatically change the content of a <div> upon its creation in a page.

What I'm doing, specifically, is to use jquery to load django templates into the page. Some of those templates contain s that I want to immediately alter as soon as they come into the browser.

As a simple example, what I'd like is for the following to work:

$(".load_into").live("load",funct开发者_JAVA技巧ion(){$(this).html("Dynamic content!");});

However, "load" isn't an eventtype that can be used with <div>s, so that doesn't actually work. Any thoughts on simple ways to do this? Thanks for any help!


What you probably want here is the livequery plugin, using it would look like this:

$(".load_into").livequery(function(){
  $(this).html("Dynamic content!");
});

Unlike .live() which listens for events, .livequery() looks for new elements, and will run the function you give it on all new elements as it finds them.


you're probably looking for the ready-callback function

$(".load_into").ready(function(){$(this).html("Dynamic content!");});

this will not run after the div is created in the browser the common way would be to tie this callback to the document creation:

$(document).ready(function(){$(".load_into").html("Dynamic content!");});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜