This is the JSON and the html code... I've tried many things but I can't get it to work. I am new at JSON and I can do with simple class but with these nested classes I have an issue ... Would appreciate any help I can get.
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1,
shrink-to-fit=no">
<link href="https://fonts.googleapis.com/css?
family=Lato:300,400,700,900" rel="stylesheet"> <link rel="stylesheet"
href="css/reset.css">
<link rel="stylesheet" href="css/style.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script src="script/script.js"></script>
<title>Grean Earth</title>
</head>
<body>
<section id="hero">
<ul id="heroSlajder">
<li class="sliderPics ">
<img class="sliderPictures " src="">
</li>
<li class="sliderPics showing">
<img class="sliderPictures " src="">
</li>
<li class="sliderPics ">
<img class="sliderPictures" src="">
</li>
</ul>
</body>
</html>
JSON:
{
"hero": {
"heroSlajder": [ {
"sliderPics":[ {
"sliderPictures": "./images/img/slider-1.png"
}
]],
"heroSlajder": [ {
"sliderPics":[ {
"sliderPictures": "./images/img/slider-2.png"
}
]],
"heroSlajder": [ {
"sliderPics":[ {
"sliderPictures": "./images/img/slider-3.png"
}
]]
}
}
This is the JavaScript function that I use to get images from JSON:
$(document).ready( function () {
var obj = JSON.parse(db); heroDivData(obj);
function heroDivData(obj){ for (i in obj.hero.heroSlajder.sliderPics){
var j = parseInt(i)+1;
$('.sliderPics:nthchild('+j+').sliderPictures').attr('src',obj.hero.heroSlajder.sliderPics[i].sliderPictures); } }
Update: I tried this but still nothing
{
"hero": [ {
"heroSlajder": [ {
"sliderPics":[ {
"sliderPictures": "./images/img/slider-1.png"
}
,
{
"sliderPictures": "./images/img/slider-2.png"
}
,
{
"sliderPictures": "./images/img/slider-3.png"
}
]
}
]
}]
}