This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<div> | |
<div> | |
<div id="cont" class="content"> | |
<p class="p1">Paragrafo 1</p> | |
<p class="p2">Paragrafo 2</p> | |
<p class="p3"> | |
<input name="nome" value="teste" /> | |
</p> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const content = document.querySelector('.content'); | |
let p = document.querySelector('p'); | |
let pList = document.querySelectorAll('p'); | |
console.log(p); // <p class="p1">Paragrafo 1</p> | |
p = document.querySelector('.content > p.p3'); | |
console.log(p); // <p class="p3">...</p> | |
console.log(pList); // [p.p1, p.p2, p.p3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log(document.getElementById('cont')); // <div id="cont" class="content">...</div> | |
console.log(document.getElementsByClassName('content')); // [div#cont.content] | |
console.log(document.getElementsByTagName('div')); // [div, div, div#cont.content] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let p = document.querySelector('.content > p'); | |
console.log(document.parentNode); // <div id="cont" class="content">...</div> | |
console.log(document.parentElement); // <div id="cont" class="content">...</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const p = document.querySelector('.p2'); | |
console.log(p.previousElementSibling); // <p class="p1">Paragrafo 1</p> | |
console.log(p.nextElementSibling); // <p class="p3">...</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const p = document.querySelector('.content'); | |
console.log(p.children); // [p.p1, p.p2, p.p3] | |
console.log(p.childNodes); // [text, p.p1, text, p.p2, text, p.p3, text] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const p = document.querySelector('.p1'); | |
HTMLElement.prototype.parentsByTagName = function(tn) { | |
let arrayElements = []; | |
let currentEl = this; | |
while (currentEl) { | |
currentEl = currentEl.parentElement; | |
if (!currentEl) return arrayElements; | |
if (currentEl.tagName === tn) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const p = document.querySelector('.p1'); | |
const parents = function (el) { | |
let arrayElements = []; | |
let currentEl = el; | |
return function findParentByTagName(tn) { | |
currentEl = currentEl.parentElement; | |
if (!currentEl) return arrayElements; | |
if (currentEl.tagName === tn) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const div = document.createElement('DIV'); | |
console.log(div); //<div></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); | |
console.log(svg); //<svg></svg> |
OlderNewer