Creating a jQuery Plugin Job On a Dynamically Added Element

Well, I have this plugin (http://timeago.yarp.com/) that works great with an existing element. However, when I dynamically add an element, the effect does not apply to this new element. How can I make the plugin work with dynamically added elements?

The syntax for the plugin is:

$("abbr.timeago").timeago();
+3
source share
3 answers

This is a known issue when adding dynamic elements. You need to re-confirm the item you just added.

So for example:

$.ajax({
  url: "example.html",
  cache: false,
  success: function(html){
    var $jqueryElement = $(html);
    $("abbr.timeago", $jqueryElement).timeago();
    $("#results").append($jqueryElement);
  }
});

In the example above, rebinds abbr.timeago returns from example.html and adds them to the DOM.

+6
source

not sure but you can try something like this

$("abbr.timeago").ready(function(){

$(this).timeago();

});
+2
source

, JS , .timeago() .

0

Source: https://habr.com/ru/post/1793572/


All Articles