I'm currently in the process of developing a search platform. I have three static divs on the search results page that display certain content, all containing similar code.
For example:
<div id="result" class="card">
<img src="hello.png" class="card_img" alt="result image">
<h4>OFFLINE</h4>
<p>Yes!!</p>
</div>
<div id="result" class="card">
<img src="hello.png" class="card_img" alt="result image">
<h4>OFFLINE</h4>
<p>Yes!!</p>
</div>
<div id="result" class="card">
<img src="hello.png" class="card_img" alt="result image">
<h4>OFFLINE</h4>
<p>Yes!!</p>
</div>
I am seeking guidance on how to dynamically loop through the contents of this div when a user clicks on a button:
<button id="search" class="btn" value="Search">
I want the contents in this div to be dynamic, negating the need for multiple static divs. How can I achieve this using JavaScript?
EDIT
I am now looking for a way to populate a div
with children that match the data from the JSON response below, creating a dynamically loaded list:
[{
"name": "Malkov Chicken",
"location": "New York",
"meals": 5,
"close_time": 1567289876354
},
{
"name": "Delicious Chops",
"location": "San Francisco",
"meals": 15,
"close_time": 1567289876354
},
{
"name": "Banana cultshop",
"location": "New York",
"meals": 8,
"close_time": 1567289876354
}]
The div should populate with data from the JSON list and dynamically create div elements based on the number of responses received from the JSON. For instance, if there are 5 objects in the JSON response, there should be 5 corresponding divs created dynamically.