Note: This question is different than the one posed in posts about what querySelectorAll and getElementsById. Because I also can't change the image
I am trying to use query selectors to change HTML content in the following ways:
- to change the leading h1 text from white to blue
- to change the only image on the page to a different image
- to change all the paragraphs text color from purple to black
I tried using document.querySelector and document.querySelectorAll. I was able to successfully change the h1 text to blue. However, I was not able to change the image. Nor was I able to change the paragraphs to be black.
const blueh1 = document.querySelector('h1');
blueh1.style.color = 'blue'
const mainImage = document.querySelector('.mainmain');
mainImage.src = 'img/jevon_in_barra.jpg';
console.log(mainImage);
const paragraphs = document.querySelectorAll('p');
paragraphs.style.color = 'black';
HTML code below:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Marketing Page Home</title>
<link href="./css/index.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Indie+Flower|Roboto" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Poppins&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,800&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/a791a74a1f.js" crossorigin="anonymous"></script>
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<container>
<nav>
<a href="index.html">Home</a>
<a href="about.html">About Us</a>
<a href="#">Sign Up</a>
<a href="https://expat-journal.emilyelri.now.sh/login">Log In</a>
<a href="#">Contact</a>
</nav>
</container>
<container class="h1-container">
<h1 class="logo-font">Expat Journal</h1>
</container>
<section class="top">
<container>
<h2>Show and Tell, except for Expats</h2>
<h3>A platform for travel story-telling</h3>
<button>
<a href="https://expat-journal.emilyelri.now.sh/login" class="mainmain">Get started for free</a>
</button>
</container>
</section>
<section class="middle">
<img src="img/travel-meeting.jpg" alt="">
</section>
<section class="bottom">
<container>
<container class="photos-container">
<i class="far fa-image"></i>
<h3>Photos</h3>
<p>Show off pics of the amazing places you've been around the world. Users can visit site and see photos laid out in a grid, with the ability to like, comment and share!</p>
</container>
<container class="stories-container">
<i class="fas fa-video"></i>
<h3>Stories</h3>
<p>Keep your friends and family updated with beautiful story content. You can select to show for a limited period of time or retain permanently on your profile.</p>
</container>
<container class="connect-container">
<i class="fas fa-user-friends"></i>
<h3>Connect</h3>
<p>Users can follow your profile as well as like, comment and share your content. Inspire others to travel and share their experiences!</p>
</container>
</container>
</section>
<footer>
<nav class="footer">
<a href="index.html">Home</a>
<a href="about.html">About Us</a>
<a href="#">Sign Up</a>
<a href="https://expat-journal.emilyelri.now.sh/login">Log In</a>
<a href="#">Contact</a>
</nav>
</footer>
</body>
<script type="text/javascript" src="index.js"></script>
</html>
Nothing is logging to the console. I'm getting a reference error that says document is not defined.