See the Pen Untitled by dupont (@dupontcodepen) on CodePen.
| Property / Method | Description |
|---|---|
| element.appendChild() | Adds a new child node, to an element, as the last child node |
| element.attributes | Returns a NamedNodeMap of an element's attributes |
| element.childElementCount | Returns the number of child elements an element has |
| element.childNodes | Returns a collection of an element's child nodes (including text and comment nodes) |
| element.children | Returns a collection of an element's child element (excluding text and comment nodes) |
| element.classList | Returns the class name(s) of an element |
| element.className | Sets or returns the value of the class attribute of an element |
| element.cloneNode() | Clones an element |
| element.contains() | Returns true if a node is a descendant of a node, otherwise false |
| element.contentEditable | Sets or returns whether the content of an element is editable or not |
| element.firstChild | Returns the first child node of an element |
| element.firstElementChild | Returns the first child element of an element |
| element.getAttribute() | Returns the specified attribute value of an element node |
| element.getAttributeNode() | Returns the specified attribute node |
| element.getElementsByClassName() | Returns a collection of all child elements with the specified class name |
| element.getElementsByTagName() | Returns a collection of all child elements with the specified tag name |
| element.hasChildNodes() | Returns true if an element has any child nodes, otherwise false |
| element.id | Sets or returns the value of the id attribute of an element |
| element.innerHTML | Sets or returns the content of an element |
| element.insertBefore() | Inserts a new child node before a specified, existing, child node |
| element.lastChild | Returns the last child node of an element |
| element.lastElementChild | Returns the last child element of an element |
| element.nextSibling | Returns the next node at the same node tree level |
| element.nextElementSibling | Returns the next element at the same node tree level |
| element.nodeName | Returns the name of a node |
| element.nodeType | Returns the node type of a node |
| element.nodeValue | Sets or returns the value of a node |
| element.parentNode | Returns the parent node of an element |
| element.parentElement | Returns the parent element node of an element |
| element.previousSibling | Returns the previous node at the same node tree level |
| element.previousElementSibling | Returns the previous element at the same node tree level |
| element.querySelector() | Returns the first child element that matches a specified CSS selector(s) of an element |
| element.querySelectorAll() | Returns all child elements that matches a specified CSS selector(s) of an element |
| element.removeAttribute() | Removes a specified attribute from an element |
| element.removeChild() | Removes a child node from an element |
| element.replaceChild() | Replaces a child node in an element |
| element.setAttribute() | Sets or changes the specified attribute, to the specified value |
| element.setAttributeNode() | Sets or changes the specified attribute node |
| element.style | Sets or returns the value of the style attribute of an element |
| element.tagName | Returns the tag name of an element |
| element.textContent | Sets or returns the textual content of a node and its descendants |
| nodelist.item() | Returns the node at the specified index in a NodeList |
| nodelist.length | Returns the number of nodes in a NodeList |
https://github.com/dupontdenis/tri.git
L'idée est de trié un tableau en mémoire et de repercuter sur le DOM le changement.
See the Pen Untitled by dupont (@dupontcodepen) on CodePen.
window.onload = function() {
const $ = document.querySelector;// TypeError: Illegal invocation
const el = $('.some-element');const $ = document.querySelector.bind(document);
// Or:
const $ = (...args) => document.querySelector(...args);
<!DOCTYPE html>
<div id="menu">
<button data-action="save">Save</button>
<button data-action="load">Load</button>
<button data-action="search">Search</button>
</div>
class Menu {
constructor(elem) {
this._elem = elem;
}
save() {
alert('saving');
}
load() {
alert('loading');
}
search() {
alert('searching');
}
onClick(event) {
let action = event.target.dataset.action;
if (action) {
this[action]();
}
};
}
new Menu(menu);
node | element |
function buildTable(data) { var table = document.createElement("table");
var fields = Object.keys(data[0]); console.log(fields); var headRow = document.createElement("tr"); fields.forEach(function(field) { var headCell = document.createElement("th"); headCell.textContent = field; headRow.appendChild(headCell); }); table.appendChild(headRow); data.forEach(function(object) { var row = document.createElement("tr"); fields.forEach(function(field) { var cell = document.createElement("td"); cell.textContent = object[field]; if (typeof object[field] == "number") cell.style.cssText = "background-color:black;color:white;text-align:right;" row.appendChild(cell); }); table.appendChild(row); }); return table; } document.body.appendChild(buildTable(PERSON)); | function buildTable(data) { const table = document.createElement("table"), fields = Object.keys(data[0]); let template = `<tr><th>${fields[0]}</th><th>${fields[1]}</th><th>${fields[2]}</th></tr>`; table.insertAdjacentHTML("afterBegin", template); for (let { name, age, country } of data) { template = `<tr><td>${name}</td><td>${age}</td><td>${country}</td></tr>`; table.insertAdjacentHTML("beforEEnd", template); } return table; } document.body.appendChild(buildTable(PERSON)); |
Screen → the full screen of the monitor (screenX/Y)
Position will always be relative to the physical screen's viewport.
Client → the client viewport of the browser (clientX/Y)
If you click in the left top corner the value will always be (0,0) independent on scroll position.
Document → the complete document/page (pageX/Y)
Note that pageX/pageY on the UIEvent object are not standardized.
All values are in pixels.
