How do I make this function work with dynamically generated elements? It works when element is loaded along with the page, but when I generate the div with ajax the function does not work!
$('.rating1').likeDislike({
reverseMode: true,
disabledClass: 'disable',
click: function (value, l, d, event) {
var likes = $(this.element).find('.likes');
var dislikes = $(this.element).find('.dislikes');
likes.text(parseInt(likes.text()) + l);
dislikes.text(parseInt(dislikes.text()) + d);
}
});
The ajax code:
$.ajax({
url : link,
type: 'GET',
dataType: "html",
preocessData: false,
})
.done(function(msg2){
// Adiciono esse elemento dinamicamente
<div class="rating rating1">
<button class="btn btn-default like">Like</button>
<span class="likes">0</span>
<button class="btn btn-default dislike">Dislike</button>
<span class="dislikes">0</span>
</div>
}
})