DOM
Last updated
Clone the .
Please refer to if you need a refresher.
Create an empty function called makeBox
. makeBox
will create a new HTML element on screen each time it's called.
If you were to write out the HTML element it would look like the following.
Specifically makeBox
needs 7 steps.
Create the p
paragraph tag. Something like: var pOne = document.createElement('p');
Fill the tag with text using innerText
. Something like: pOne.innerText = 'haha';
Create a second p
paragraph tag.
Fill the tag with text using innerText
.
Create the div
tag.
Put both p
tags into the div
tag using appendChild
. Something like: divTag.appendChild( pOne );
Put the div
tag onto the page with document.body.appendChild.
Edit style.css
so you can clearly identify the box.
Call the makeBox
function inside of script.js
.
Create a function makeCard
that creates card elements with the following HTML structure. See the next code snippet for how to set an img
tag's src
attribute in JS.
Here is how we might set an img
tag's src
attribute in JS.
Edit style.css
for makeCard
to better identify our cards in the UI.
Call makeCard
in script.js
.
Update the makeBox
function to also render a button with the words "Make Card". The corresponding HTML might look like the following, but we will construct it using JS.
Trigger the makeCard
function when the user clicks the "Make Card" button by calling addEventListener
on the button with makeCard
as the callback function.
Change the makeCard
function so that it creates multiple cards when the button is clicked. We can create and append elements in a loop inside makeCard
.
Get another image URL from the internet
Search for an image
Right click on the image in Chrome
Select "Copy Image Address"
Put these images into an array and loop over each image in the array to create the set of cards
Change makeCard
so that when the user clicks, she gets a single card with a random image.
Add an input to the box created by makeBox
. The user can fill out a number X in the input. When they click the button, X images appear inside the new card.