开发者

Adding img to div on load

开发者 https://www.devze.com 2023-03-14 20:15 出处:网络
Is there a way to add a specific img to every element of class .myClass on its creation? I tried this, and it doesn\'t work..

Is there a way to add a specific img to every element of class .myClass on its creation?

I tried this, and it doesn't work..

$('.myClass').live('load', functio开发者_StackOverflow社区n() {
    $(this).prepend('<img src="..." />');
});

My final goal is, to be able to create a modal box (or a light box) by just creating a div of class myClass, so I don't have to add the closing image tag (for closing the modal box) for each modal box


There might be a better way than what i'm about to suggest, but i use livequery to get that working. Livequery listen's for the moment the element appears in the DOM.

$('.myClass').livequery(function() {
    $(this).prepend('<img src="..." />');
});

If anyone knows of a better way, i'd love to see it too

0

精彩评论

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