write a simple JavaScript program that will recursively walk the DOM for an associated HTML file and print the types of the elements encountered (embedded data need not be printed, we are just interested in the structure), each preceded by an integer reflecting the element’s nesting level within the hierarchical structure of the HTML document. Thus,<HEAD>and <BODY> would be at the second level (‘2’) while <HTML>, would naturally be at the first level (‘1’). You should also print the closing tags for each element found to make the nesting clear. Thus, your output should look something like the following:
1 <HTML>
2<HEAD>
element types in “<HEAD></HEAD>” labelled appropriately
2 </HEAD>
2<BODY>
element types in “<BODY></BODY>” labelled appropriately
2</BODY>
1</HTML>
Let's say this following is our html code..
<!doctype html> <HTML> <HEAD> </HEAD> <BODY> <P> Top 3 Channel 3 Thai actresses: </P> <ol> <li>U</li> <li>V</li> <li>B</li> </ol> <div id="idDiv"></div> <script type="text/javascript" src="script.js"> </script> <BODY> </HTML>
JavaScript code:
var element = document.getElementById("idDiv"); function printNodeInfo(node) { if (node.nodeType == Node.TEXT_NODE && !node.nodeValue.trim()) { return; } element.innerHTML += node; element.innerHTML += ", nodeName: " + node.nodeName; element.innerHTML += ", nodeType: " + node.nodeType; element.innerHTML += ", innerHTML: " + node.innerHTML; element.innerHTML += "<br>"; } // Get a handle of the ordered-list node. var orderedlistNode = document.getElementsByTagName("ol")[0]; theDOMElementWalker(orderedlistNode); function theDOMElementWalker(node) { if (node.nodeType == 1) { node = node.firstChild; while (node) { theDOMElementWalker(node); printNodeInfo(node); node = node.nextSibling; } } } element.innerHTML += "<br>";
Write a simple JavaScript program that will recursively walk the DOM for an associated HTML file ...
Javascript to edit a HTML file. Where to begin? <!doctype html> <html> <head> <meta charset="utf-8"> <title>TODO: Change The Title</title> </head> <body> <h1></h1> <p>First paragraph.</p> <p class="intro">Second <span>paragraph</span>.</p> <button id="start">Start</button> <main> </main> <!-- Test 6: DOM Programming You MAY consult the notes for week 7, but you MAY NOT discuss this test or your code with any other students. All work must be your own. Instructions: 1. Put all solution code in a file named solution.js. When you upload your solution to...
Using HTML and JavaScript. For this assignment you should submit a single zip file that contains the following two files: index.html script.js index.html should be a skeleton HTML page. So it should have the following tags: doctype html head meta title body script If you were to open index.html without including the associated JavaScript it should be entirely blank. You should then use JavaScript to create all of the content of this page and append it to the body of...
Need help with creating this JavaScript file. I'm not sure where or how to begin. 1. You are working solely with the DOM object. Thus, you should be coding primarily in the js file. You must use the addEventListener, in addition you may need to use id and class attributes as needed. The .html and .css files have been provided to you. See the .png files for an example of what is expected. 2. Place the javaScript file in its...