Skip to content

Instantly share code, notes, and snippets.

Avatar

Amarachi Amaechi amycruz97

View GitHub Profile
View template literals.js
//Using Template literals and injecting it to the DOM with insertAdjacentHTML() method
let newDog = `
<div class="dog">
<img src="https://picsum.photos/id/237/500/500/" alt="dog"/>
<h2>My name is Roviel and i love playing and eating</h2>
<p class="moreInfo">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque
View template literals.js
//Using Template literals and injecting it to the DOM with createContextualFragment() method
let newDog = `
<div class="dog">
<img src="https://picsum.photos/id/237/500/500/" alt="dog"/>
<h2>My name is Roviel and i love playing and eating</h2>
<p class="moreInfo">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Qui
View template literals.js
//Using Template literals
let newDog = `
<div class="dog">
<img src="https://picsum.photos/id/237/500/500/" alt="dog"/>
<h2>My name is Roviel and i love playing and eating</h2>
View index.js
let newDog = document.createElement('div')
newDog.classList.add('dog')
const myImage = document.createElement('img')
myImage.src="https://picsum.photos/id/237/500/500";
myImage.alt='Dog photo'
View style.css
.dog{
background-color: pink;
width: 40vw;
margin: 0 auto;
border-radius: 10px;
padding: 2rem;
text-align: center;
}
img{
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dog profile</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
View index.js
// we created a myBtn function stating that when ever we click btn, it should alert 'you clicked on the button class'
function myBtn() {
alert('you clicked on the button class')
};
// btn class does not exist in our html page therefore this will throw an error of addEventListener of null
const btn = document.querySelector(".btn").addEventListener('click',myBtn)
View index.html
//This is a div with a class of container
<div class="container"></div>