How To Add A Class In JS On The Basis Of JSON?
File.php I have a html/php code as shown below. The following code is inside File.php file.
toggle_multi_tiles))
Solution 1:
Like this?
const admin = {"toggle_multi_tiles":["1","3","2"]};
const toggle = admin.toggle_multi_tiles;
const wrapper = document.querySelector(".wrapper");
let html = [];
for (let i=0;i<toggle.length; i++) {
html.push(`<img class="featured-block__item${i===0?" featured-block__item-active":""}" src="https://via.placeholder.com/400x300?text=picture%20${toggle[i]}" alt=""> <!-- ${toggle[i]} -->`)
}
wrapper.innerHTML=html.join("\n")
.featured-block__item-active { border:3px solid red }
<div class="wrapper">
</div>
Post a Comment for "How To Add A Class In JS On The Basis Of JSON?"