Question

Using JavaScript. (I'm using Notepad++)

There are three paragraph elements on the page. They have the following ids: p2 p3 1. Create three variables, with a descriptive name of your choice, that will be used to hold the three paragraph elements in the web page. You will use these variables in step 2. 2. Use the document.getElementByld method to assign the paragraph elements to your three variables. assign the paragraph with the id p1 to your first variable assign the paragraph with the id p2 to your second variable assign the paragraph with the id p3 to your third variable 3. Use the supplied paragraph string constants: PARA1, PARA2, PARA3 to do the following (Do not change the names, and do not modify the text of these constants): 1. Update the paragraph with the id of p1, using its innerHTML property, with the PARA1 string 2. Update the paragraph with the id of p2, using its innerHTML property, with the PARA2 string 3. Update the paragraph with the id of p3, using its innerHTML property, with the PARA3 string constant. Use the variable you used to hold p1 constant.. Use the variable you used to hold p2. constant. Use the variable you used to hold p3.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new web page with name "JavaScriptDemo.html" is created, which contains following code, also this html web page is using javascript file with name "main.js". Following section gives details about each of the above file

JavaScriptDemo.html

<html>

<head>

<!-- title for web page -->

<title> Javascript DOM Manipulation </title>

</head>

<body>

<!-- para1 -->

<p id="p1">Paragraph 1</p>

<!-- para2-->

<p id="p2">Paragraph 2</p>

<!-- para3 -->

<p id="p3">Paragraph 3</p>

<!-- <script> is used to refer to external javascript file -->

<script src="main.js"></script>

</body>

</html>

main.js : Following is javascript code for document object manipulation

// declaring three variables in javascript

var HTMLPara1;

var HTMLPara2

var HTMLPara3

// Access DOM element para1 using javascript document.getElementById() method.

// selecting para 1

HTMLPara1 = document.getElementById("p1");

// selecting para 2

HTMLPara2 = document.getElementById("p2");

// selecting para 3

HTMLPara3 = document.getElementById("p3");

//changing text of paragraphs using innerHTML property

//changing text for P1

HTMLPara1.innerHTML = "PARA1";

//changing text for P2

HTMLPara2.innerHTML = "PARA2";

//changing text for P32

HTMLPara3.innerHTML = "PARA3";

=====================================================================================

Output : Open the web page in the browser , will get the screen as shown below

Screen 1 :

Javascript DOM Manipul x JavaScriptDemo.html PARA1 PARA2 PARA3

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Using JavaScript. (I'm using Notepad++) There are three paragraph elements on the page. They have the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT