Last active
December 23, 2016 03:47
-
-
Save ZoomZhao/856ce81786aca14e3845124b67caf308 to your computer and use it in GitHub Desktop.
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
// 1 | |
const uls = document.getElementByTagName('ul') | |
for(u of uls) { | |
u.classList.add('bar') | |
} | |
// 2 | |
document.querySelector('#list > li:nth-child(10)').remove() | |
// 3 | |
const list = document.getElementById('list') | |
const child = document.querySelector('#list > li:nth-child(500)') | |
if (child) { | |
const next = child.nextSibling | |
const element = document.createElement('li') | |
element.innerText = '<v2ex.com />' | |
if (next) { | |
list.insertBefore(element, next) | |
} else { | |
list.appendChild(element) | |
} | |
} | |
// 4 | |
const list = document.getElementById('list') | |
list.addEventListener('click', function(e) { | |
let target = e.target | |
let last = target.closest('#list > li') | |
/* while (target.id !== 'list') { | |
last = target | |
target = target.parentNode | |
} */ | |
let i = 1; | |
while (last = last.previousSibling) { | |
if (last.nodeType === 1) { ++i } | |
} | |
alert(i) | |
}, false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
getElementsByTagName 落下s 😄