I have made a NEWS website it consists of 3x4 grids. I want to populate these grids with NEWS title, description, image, etc. I am not able display anything on my website.
HTML code:
<div class="Article">
<div class="col-md-4" title="News">
<h3></h3>
<p></p>
</div>
<div class="col-md-4" title="News">
<h3></h3>
<p></p>
</div>
<div class="col-md-4" title="News">
<h3></h3>
<p></p>
</div>
</div>
<div class="Article">
<div class="col-md-4" title="News">
<h3></h3>
<p></p>
</div>
<div class="col-md-4" title="News">
<h3></h3>
<p></p>
</div>
<div class="col-md-4" title="News">
<h3></h3>
<p></p>
</div>
</div>
<div class="Article">
<div class="col-md-4" title="News">
<h3></h3>
<p></p>
</div>
<div class="col-md-4" title="News">
<h3></h3>
<p></p>
</div>
<div class="col-md-4" title="News">
<h3></h3>
<p></p>
</div>
</div>
<div class="Article">
<div class="col-md-4" title="News">
<h3></h3>
<p></p>
</div>
<div class="col-md-4" title="News">
<h3></h3>
<p></p>
</div>
<div class="col-md-4" title="News">
<h3></h3>
<p></p>
</div>
</div>
</div>
JS code:
$(document).ready(function() {
var news_source =["the-times-of-india","business-insider","techcrunch","bbc-sport"];
for(var i=0;i<news_source.length;i++){
$.getJSON('https://newsapi.org/v1/articles?source='+ news_source[i] +'&sortBy=top&apiKey=my-api-key',function (json) {
console.log(json);
for(var j=0;j<3;j++){
$(".Article News h3").eq(j).html(json.articles[j].title);
$('.Article News p').eq(j).html(json.articles[j].description);
}
});
}
});
I am not able to display any data using JSON I have made array of website sources i.e news_sources[] because each source returns 4 to 5 objects so that I can display it in grids, in total I have made 12 grids. I want to display Business NEWS in first row, sports NEWS in second row, tech NEWS in third row and so on in grid system that's why I have made array of news_sources[] to display articles from different web sources.
JSON data:
Website Layout:


iin your selcondforloop, you should change one of them fromito something else.<p>tag and title of NEWS in<h3>tag.