javascript - Onclick for arrays in JSON -
i'm retrieving data through api, , creating list using js. wondering if possible create onclick function every element in array element of json. elements being displayed, nothing happens when click them. also, possible pass on data in json redirection new page?
my code follows:
var url = "https://api.nytimes.com/svc/movies/v2/reviews/all.json?api-key=b5f6bc931d6e446a998eb063a7c13d8e"; $.ajax({ url: url, method: 'get', datatype: 'json', success: function (data) { var data = data; details(data); (var = 0; < object.keys(data.results[0]).length; i++) { document.getelementbyid("movlist"); var item = document.createelement('li'); item.classname = 'listele'; var itempicdiv = document.createelement('div'); itempicdiv.classname = 'picdiv'; var itempic = document.createelement('img'); itempic.classname = 'pic'; itempic.src = data.results[i].multimedia.src; var itemnamediv = document.createelement('div'); itemnamediv.classname = 'namediv'; var itemname = document.createtextnode(data.results[i].display_title); itemname.classname = 'name'; itempicdiv.appendchild(itempic); itemnamediv.appendchild(itemname); item.appendchild(itempicdiv); item.appendchild(itemnamediv); list.appendchild(item); } } }).done(function (result) { console.log(result); }).fail(function (err) { throw err; }); function details(data) { (var j = 0; j < object.keys(data.results[0]).length; j++) { var t = data.results[j]; t.onclick = function () { location.href = 'detail.html'; } } }
Comments
Post a Comment