Fake News
This exercise is about modifying the content of a page in your web browser using Javascript. As we have said, Javascript has access to the current page via the Document Object Model or DOM. In your browser, the variable document represents the current document and your code can use it to read and write to the current page. In this exercise we will use the developer tools Javascript console to write Javascript to access parts of the main page of a newspaper site and, just for fun, modify their contents. The instructions here relate to Chrome but some variation will work in any browser.
The console allows you to run Javascript code in the context of the current page, so the document variable will represent the page you are viewing. Write Javascript code to select all of the headline elements, so if you saw that they were all <h3> elements you might write
headlines = document.getElementsByTagName("h3")
Take the first of these and find the HTML content of the heading:
headlines[0].innerHTML
Now modify this to add your own message to the page
headlines[0].innerHTML = "COMP249 Found to be Best Unit in the Universe!"
Check the page to see your updated headline.
Ok, so we can fake the news, that's good but we can go further.
Now, be careful to only use your new-found powers for good, not evil.
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here telegraphIndia web site is used for this demonstration.
Screen 1 :Edited heading first h3 .
a for loop that changes the content of all of the headlines to your chosen message :
headlines = document.getElementsByTagName("h3");
for(i=0;i<headlines.length;i++){headlines[i].innerHTML = "COMP249 Found to be Best Unit in the Universe!";}
Screen 2 :
a function that takes your new message as an argument and modifies the headlines when it is called :
//function defination
function changeHeading(message) {
headlines = document.getElementsByTagName("h3");
for (i = 0; i < headlines.length; i++)
{
headlines[i].innerHTML = message; }
}
changeHeading("myHeading");//function call
Screen 3 :
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
Fake News This exercise is about modifying the content of a page in your web browser using Javascript. As we have said, Javascript has access to the current page via the Document Object Model or DOM....
WEB230 - JavaScript 1 Assignment 6a Use Events and DOM manipulation to create a playable Tic Tac Toe game. Do the following using JavaScript. Do not modify the HTML file. When you see this symbol: save and refresh the browser (this should happen automatically if you are using Brackets with Live Preview), then check your code to make sure it is working before you proceed. 1. Create two variables called "playerX" and "playero". Set them to the DOM element with...
NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...
You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...