Apply widget to current and future page elements
Update : I had to change the text to explain my exact problem.
I have a 3th party library for tooltips. It works like this
jQuery("a").tooltip();
Ho开发者_Go百科w can I attach this to all future "a" elements added using ajax on this page ?
How can I attach this to all future "a" elements added using ajax on this page ?
Just call:
jQuery("a").tooltip();
again in each AJAX call's .success()
handler.
If the plugin is written properly it'll ignore any links that have already had this applied to them. Otherwise, you'll need to change the selector so that it only picks the ones added by the AJAX call.
There are several ways:
Give all dynamic future elements a certain class (like
dynamic
) and use a CSS rule like this.span.dynamic { display: block; }
Make sure all dynamic elements have a certain parent element in the page (or at least a parent element with a certain class:
#dynamicParent span { display: block; } <-- Select single element by ID div.dynamicParent span { display: block; } <-- all divs with this class
Try this:
$("head").append("<link>");
css = $("head").children(":last");
css.attr({
rel: "stylesheet",
type: "text/css",
href: "link_that_point_to_the_css"
});
精彩评论