For the HTML directly below, I would like to add the contents similar to the second HTML called results using a javasript function
For the HTML directly below, I would like to add the contents similar to the second HTML called results using a javasript function
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title></title>
<script src="assets/js/script.js" defer></script>
<link rel="stylesheet" href="assets/css/style.css" />
</head>
<body>
<header>
<div class="site-title">Home</div>
<nav>
<a href="/">Home</a>
<a href="results.html">Results</a>
</nav>
</header>
function createEle(linkObj) {
const { animal, img, url } = linkObj;
const anchor = document.createElement("a");
anchor.setAttribute("href", url);
}
createEle (animalArr);
I am not sure how to finish this function as it needs to use the array to create all the elements including the section elements by calling the function once
<div class="big-hero">
<h1>Big Cats </h1>
</div>
<div class="content"></div>
</body>
</html>
Below is what the HTML should look like using the javascript function:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Results</title>
<link rel="stylesheet" href="assets/style.css" />
</head>
<body>
<div class="wrapper">
<header>
<div class="site-title">Results</div>
<nav>
<a href="/">Home</a>
<a href="results.html">Results</a>
</nav>
</header>
<div class="big-hero">
<h1>Big Cats Are Awesome</h1>
</div>
<div class="content">
<section class="Cheetah">
<a href="https://en.wikipedia.org/wiki/Cheetah" target="_blank">
<h2>Cheetah</h2>
<img src="assets/images/cheetah.jpg" alt="Cheetah" />
</a>
</section>
<section class="Leopard">
<a href="https://en.wikipedia.org/wiki/Leopard" target="_blank">
<h2>Leopard</h2>
<img src="assets/images/leopard.jpg" alt="Leopard" />
</a>
</section>
</div>
</div>
</body>
</html>
And below is the array to be used:
const animalArr = [
{
animal: "Cheetah",
img: "assets/images/cheetah.jpg",
url: "https://en.wikipedia.org/wiki/Cheetah",
},
{
animal: "Leopard",
img: "assets/images/leopard.jpg",
url: "https://en.wikipedia.org/wiki/Leopard",
},
];
The javascript function cannot use innertext/innerhtml so the function should be similar to.
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)