event onclick button generated by array

0

I have the following code, and I want that by clicking the button execute the onclik function with the indicated parameter.

function getcontent() {
$.ajax({
    url: 'https://example.io/blog',
    type: 'GET',
    success: function(result) {
        var blog = [];
        $.each(result, function(key, content) {
            blog.push("<div class='article'>");       
            blog.push("<a class='titol'>" + content.titol + "</a>");
            blog.push("<p class='autor'>" + content.autor + "</p>");
            blog.push("<p class='data'>"+content.data+"</p>");
            blog.push("<div class='content'>"+content.contingut+"</div>");
            blog.push('<button onclick="getcontentById("'+content.id+'")">more</button>');
            blog.push("</div>");
        });

        $("#content").empty();
        $("#content").html(blog.join(""));
    }
});
}
    
asked by francesc 23.02.2018 в 23:13
source

1 answer

0

I solved it by using the id via link i in html using a javascript function:

blog.push("<a href='detall.html?id="+content.id+"' target='_blank'>more</a>");
    
answered by 28.02.2018 / 10:14
source