node

Estimated reading time: 4 minutes

childNodes

var doc = document.getElementById('main');
var doc1 = doc.childNodes;
console.log(doc1);

childNodes array

var doc = document.getElementById('main');
var doc1 = doc.childNodes[1].parentNode;
console.log(doc1);

firstChild

var doc = document.getElementById('main');
var doc1 = doc.childNodes[1].firstChild;
console.log(doc1);

lastChild

var doc = document.getElementById('main');
var doc1 = doc.childNodes[1].LastChild;
console.log(doc1);

firstElementChild

var doc = document.getElementById('main');
var doc1 = doc.childNodes[1].firstElementChild;
console.log(doc1);

LastElementChild

var doc = document.getElementById('main');
var doc1 = doc.childNodes[1].LastElementChild;
console.log(doc1);

isConnected

var doc = document.getElementById('main');
var doc1 = doc.childNodes[1].isConnected;
console.log(doc1);

previousSibling

var doc = document.getElementById('main');
var doc1 = doc.childNodes[1].previousSibling;
console.log(doc1);

previousElementSibling

var doc = document.getElementById('main');
var doc1 = doc.childNodes[1].previousElementSibling;
console.log(doc1);

nextSibling

var doc = document.getElementById('main');
var doc1 = doc.childNodes[1].nextSibling;
console.log(doc1);

nextElementSibling

var doc = document.getElementById('main');
var doc1 = doc.childNodes[1].nextElementSibling;
console.log(doc1);

nodeName

var doc = document.getElementById('main');
var doc1 = doc.childNodes[1].nodeName;
console.log(doc1);

nodeType

var doc = document.getElementById('main');
var doc1 = doc.childNodes[1].nodeType;
console.log(doc1);

cloneNode

var doc = document.getElementById('main');
var doc1 = doc.childNodes[3].previousElementSibling;
var doc2 = doc1.cloneNode(true);
console.log(doc2);

hasChildSibling

nodeValue

var doc = document.getElementById('main');
var doc1 = doc.childNodes[1].nodeValue;
console.log(doc1);

insertBefore

var docParent = document.getElementById('bio').parentNode
var doc = document.getElementById('bio')
var newNode = document.createElement("div");
newNode.id = 'before-node';
newNode.textContent = 'kamal is here ok before bio';
newNode.style.color = 'red';
docParent.insertBefore(newNode, doc);
console.log(document);

remove Child

replace child

dom, js