diff --git a/JavaScript/README.md b/JavaScript/README.md index 11f6eac..49b7631 100644 --- a/JavaScript/README.md +++ b/JavaScript/README.md @@ -5,6 +5,9 @@ - [Spread syntax](spread.js) - распаковка массива в аргументы - [fetch](fetch.js) - ... - [location.href](location.href.js) - Переход на другую страницу +- [Text Content](textContent.js) - Получить текстовое содержимое элемента +- [Add DOM Elements](addElements.js) - Добавление элементов в DOM +- [Add Class](addClass.js) - Добавление/Удаление классов ## Other - [Webpack](webpack.md) example config diff --git a/JavaScript/addClass.js b/JavaScript/addClass.js new file mode 100644 index 0000000..0ecf2dc --- /dev/null +++ b/JavaScript/addClass.js @@ -0,0 +1,5 @@ +// Use element.classList.add to add a class: +element.classList.add('my-class'); + +// And element.classList.remove to remove a class: +element.classList.remove('my-class'); diff --git a/JavaScript/addElements.js b/JavaScript/addElements.js new file mode 100644 index 0000000..85083e7 --- /dev/null +++ b/JavaScript/addElements.js @@ -0,0 +1,3 @@ +let newDiv = document.createElement('div'); +newDiv.appendChild(document.createTextNode('some text')); +document.body.appendChild(newDiv); diff --git a/JavaScript/textContent.js b/JavaScript/textContent.js new file mode 100644 index 0000000..dfcbb55 --- /dev/null +++ b/JavaScript/textContent.js @@ -0,0 +1,3 @@ +document.getElementById('element').textContent; +// If you need to target < IE9 then you need to use +document.getElementById('element').innerText;