Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- es6
- css
- css grid
- css 오버레이
- improve-iq-by-up-to-10%!
- Engoo
- flex-basis
- module wrapper function
- shit-christmas
- regExp
- 디자인패턴
- flex-grow
- select by attribute
- Sass
- img 확대
- node
- express-handlebars
- Node.js
- flexbox
- Express
- ajax
- 정규표현식
- close together
- 무료 백엔드 배포
- Prototype
- flex-shrink
- JS
- css variables
- just-one-small-sip
- Object.create
Archives
- Today
- Total
Replace & Remove Elements 본문
Replace
// Create Element
const newHeading = document.createElement("h2");
// Add an id
newHeading.id = "task-title";
// New text node
newHeading.appendChild(document.createTextNode("Task List"));
// Get the old Heading
const oldHeading = document.querySelector("#task-title");
// Parent
const cardAction = document.querySelector(".card-action");
// Replace
cardAction.replaceChild(newHeading, oldHeading);
console.log(newHeading);
Remove
// Remove element
const lis = document.querySelectorAll("li");
const list = document.querySelector("ul");
// Remove list item
lis[0].remove();
// Remove child element
list.removeChild(lis[3]);
// Classes & Attr
const firstLi = document.querySelector("li:first-child");
const link = firstLi.children[0];
let val;
// Classes
val = link.className;
val = link.classList;
val = link.classList[0];
link.classList.add("test");
link.classList.remove("test");
val = link;
// Attributes
val = link.getAttribute("href");
val = link.setAttribute("href", "http://google.com");
link.setAttribute("title", "google");
val = link.hasAttribute("title");
link.removeAttribute("title");
val = link;
console.log(val);
'2021 프론트 엔드 로드맵 따라가기 > JS' 카테고리의 다른 글
Key & Input events (0) | 2021.05.31 |
---|---|
Mouse events (0) | 2021.05.31 |
Creating Elements (0) | 2021.05.31 |
traversing dom (0) | 2021.05.30 |
Multiple Selector (0) | 2021.05.30 |
Comments