Activity 1 DOM expressions 20 points Javescript I can do the
Activity 1: DOM expressions (20 points)
Javescript: I can do the search I just need to know the Javscript code to get the information from the website as listed below.
Go to www.bing.com and perform a search using 3 distinct words of your choosing. Save the resulting page (save the complete page, not just the \"source\"). Load the page you just saved locally (Open File…).
Now, for this activity, write DOM expressions that do the following:
(3) Output to the console the
element
element
element encompassing the results of the search
(4) Output to the console the code for the \"onload\" event on the
(3) Output to the console the 2nd child node underneath the
(3) Output to the console the number of
tags in the page
(3) Output to the console the value in the search bar (you must get this from the search bar not anywhere else on the page)
(4) Make the \"Images of\" result near the top of the search result go away
Solution
Answer:-
Searching elements in DOM :
The user-triggered event, we need to find and modify elements on the page.
The childNodes, children and other helper links are helpful, but they allow to move between adjacent elements only.
Using document.write :
The document.write methods outputs a string directly into page.
document.write works:
When document is loading, a script may document.write(text) into the document. The text will be rendered same way as if it were in HTML.
Example :
<script>
document.write(\'*Hello, there!*\')
</script>
There are no restrictions on the contents of document.write. It doesn’t have to output valid tags, close them or anything.
Example :
The benefits and uses :
In most cases, it is preferred to use DOM for modifications, because it is convenient, and there is innerHTML, which is almost the same.
But document.write is the fastest way to add a script-generated text into the page.
The document.write (or writeln) allows to output a text directly into HTML. It deletes (reopens) the whole document if called after page loading.
The advantages of document.write :
