toDo.js note - 8hal/momonton_study GitHub Wiki

[question_toDo_js_01] What is the forEach? method of JSON object?

  • forEach() executes the provided callback once for each element present in the array in ascending order.
  • It is not invoked for index properties that have been deleted or are uninitialized (i.e. on sparse arrays).
const items = ['item1', 'item2', 'item3'];
const copy = [];

items.forEach(function(item){
  copy.push(item)
});

[question_toDo_js_02] What is appendChild?

  • The appendChild() method appends a node as the last child of a node.
  • You can also use this method to move an element from one element to another.

[question_toDo_js_03] What is push?

  • The push() method adds one or more elements to the end of an array and returns the new length of the array.
var animals = ['pigs', 'goats', 'sheep'];

console.log(animals.push('cows'));
// expected output: 4

console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows"]

animals.push('chickens');

console.log(animals);
// expected output: Array ["pigs", "goats", "sheep", "cows", "chickens"]

[question_toDo_js_04] What is preventDefault()?

  • The Event interface's preventDefault() method tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be.
document.querySelector("#id-checkbox").addEventListener("click", function(event) {
         document.getElementById("output-box").innerHTML += "Sorry! <code>preventDefault()</code> won't let you check this!<br>";
         event.preventDefault();
}, false);


More things

DOM Nodes

  • According to the W3C HTML DOM standard, everything in an HTML document is a node:

DOM nodes

Node Relationships

  • The nodes in the node tree have a hierarchical relationship to each other.
  • The terms parent, child, and sibling are used to describe the relationships.

Node Relationship


⚠️ **GitHub.com Fallback** ⚠️