Guest User

Untitled

a guest
Feb 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. function manipulate_01() {
  2. // DOM Maniplulation_01:
  3. // In this code we will create an element i.e., a
  4. // new div and give it some content and insert the
  5. // new div in a specific place in the DOM and also
  6. // change the heading text from DOM Changes to
  7. // DOM Manipulation and display it to the web page
  8. var btn01 = document.getElementById("btn01");
  9. // create a new div element
  10. var newDiv = document.createElement("div");
  11. // and add some content to to the div (translation is "Long life to all")
  12. var newContent = document.createTextNode("Kia ora koutou katoa!");
  13. // add the text node to the newly created div
  14. newDiv.appendChild(newContent);
  15.  
  16. // add the newly created element and its content into the DOM before <div id="div1">
  17. var currentDiv = document.getElementById("div1");
  18. document.querySelector(role = "main").insertBefore(newDiv, currentDiv);
  19.  
  20. // change heading from "DOM Changes!" to "DOM Manipulation!"
  21. var myHeading = document.getElementById("dom-manipulate");
  22. myHeading.textContent = "DOM Manipulation!";
  23. btn01.classList.add("hide-btn");
  24. }
Add Comment
Please, Sign In to add comment