开发者

Apply widget to current and future page elements

开发者 https://www.devze.com 2023-02-19 02:04 出处:网络
Update : I had to change the text to explain my exact problem. I have a 3th party library for tooltips.

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:

  1. Give all dynamic future elements a certain class (like dynamic) and use a CSS rule like this.

    span.dynamic { display: block; }
    
  2. 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"
   });
0

精彩评论

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