Skip to content

Instantly share code, notes, and snippets.

@yusk90
Last active August 29, 2015 14:22
Show Gist options
  • Save yusk90/73d41a26f019d45119e5 to your computer and use it in GitHub Desktop.
Save yusk90/73d41a26f019d45119e5 to your computer and use it in GitHub Desktop.
30.05.15
var list = document.getElementById('list');
list.classList;
list.parentNode;
list.children;
list.style.background = '#fff';
list.childNodes;
list.children[0].innerText = 'asd'; //замена элемента
list.children[0].innerText += 'asd'; //добавление текста
list.children[0].innerHTML = '<p>qwe</p>';
var div = document.createElement('div');
div.appendChild(document.createElement('input'));
document.getElementByTagName('input').name = 'some';
list.childElementCount;
list.remove();
document.querySelector('[name=some]');
Массивоподобный объект
document.querySelectorAll('li');
get - "живая" коллекция, query - "мертвая" коллекция
/*var list = document.querySelectorAll('li'),
input = document.createElement('input'),
firstItem = list[0];
firstItem.appendChild(input);
var userInput;
input.onchange = function (event) {
userInput = input.value;
return userInput;
}*/
/*window.onload = function () {
var listItems = document.querySelectorAll('li'),
arrItems = Array.prototype.slice.call(listItems);
console.log(arrItems);
}*/
/*document.DOMContentLoaded = function () {
var listItems = document.querySelectorAll('li'),
arrItems = Array.prototype.slice.call(listItems);
console.log(arrItems);
}*/
window.onload = function () {
var elem = document.querySelectorAll('li')[0];
elem.addEventListener('click', function (e) {
alert(1);
});
elem.onclick = function () {
alert(2);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment