Write a JavaScript script that updates the text color of the <header> element to red (#FF0000):You must use document.querySelector to select the HTML tagYou can’t use the JQuery APIPlease test with this HTML file in your browser:guillaume@ubuntu:~/0x15$ cat 0-main.html <!DOCTYPE html><html lang="en"> <head> <title>Holberton School</title> </head> <body> <header> First HTML page </header> <footer> Holberton School - 2017 </footer> <script type="text/javascript" src="0-script.js"></script> </body></html>guillaume@ubuntu:~/0x15$
Question
Write a JavaScript script that updates the text color of the <header> element to red (#FF0000):You must use document.querySelector to select the HTML tagYou can’t use the JQuery APIPlease test with this HTML file in your browser:guillaume@ubuntu:~/0x15
Solution
Here is a step-by-step guide on how to write a JavaScript script that updates the text color of the <header> element to red (#FF0000):
-
Open your text editor and create a new file named
0-script.js. -
In this file, you will use the
document.querySelectormethod to select the HTML tag. This method returns the first Element within the document that matches the specified selector, or group of selectors. -
To select the
<header>element, you will pass the string 'header' to thedocument.querySelectormethod. Here is how you do it:
let header = document.querySelector('header');
- Now that you have a reference to the
<header>element, you can change its text color to red (#FF0000) by setting itsstyle.colorproperty to '#FF0000'. Here is how you do it:
header.style.color = '#FF0000';
-
Save the
0-script.jsfile. -
Now, you need to link this JavaScript file to your HTML file. You can see that this is already done in the provided HTML file:
<script type="text/javascript" src="0-script.js"></script>
- Save the HTML file and open it in your web browser. You should see that the text color of the
<header>element has been changed to red.
Here is the complete JavaScript code:
let header = document.querySelector('header');
header.style.color = '#FF0000';
Please note that this code should be placed in a JavaScript file and linked to your HTML file using the <script> tag.
Similar Questions
Write a JavaScript script that updates the text color of the <header> element to red (#FF0000):You must use document.querySelector to select the HTML tagYou can’t use the JQuery APIPlease test with this HTML file in your browser:guillaume@ubuntu:~/0x15$ cat 0-main.html <!DOCTYPE html><html lang="en"> <head> <title>Holberton School</title> </head> <body> <header> First HTML page </header> <footer> Holberton School - 2017 </footer> <script type="text/javascript" src="0-script.js"></script> </body></html>guillaume@ubuntu:~/0x15$
In the following code, is the text Best School red?css:h1 { color: red;}html:<h1>Best School</h1>
In the following code, is the text Best School red?css:h1 .my_title { color: green;}.my_title { color: red;}html:<h1> <span class="my_title">Best School</span></h1>
Which CSS property is used to change the text color of an element?font-colortext-colorcolorfgcolor
How to get the <p> tag with class equal to text-dark?<h1 id="text-head">Heading 1</h1> <p id="text-body">Paragraph 1.</p> <h2 class="text-dark">Heading 2</h2> <p class="text-dark">Paragraph 2</p> <script type="application/javascript"> let p = document.___("text-dark")___</script>
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.