开发者

Highlighting text in a div, which is loaded via AJAX

I have a div element, which is loaded via AJAX. Once it's loaded, I want to highlight the text in it (the usual process, click your mouse and drag to highlight).

But since DOM is already loaded, the mouse related events are not registered for these new div's, right?

If I have a div like this

<div id="parent"></div>

And after jQuery "get" call, it becomes

<div id="parent">
  <div id="child">Hello this content is loaded via AJAX</div>
</div>

How do I rebind the div "#child" t开发者_如何转开发o mouse-related events? And exactly which events do I rebind them to?


You're looking for .live().

$("#child").live({
    click: function() {
        // do stuff
    },
    mouseover: function() {
        // do stuff
    },
    mouseout: function() {
        // do stuff
    }
});

Bind as many events as you like!


For binding events to dynamically loaded contents use jquery .live refer officially documentation as follows http://api.jquery.com/live/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜