<ul id="target">
<li>HTML</li>
<li>CSS</li>
</ul>
<input type="button" onclick="callAppendChild();" value="appendChild()" />
<input type="button" onclick="callInsertBefore();" value="insertBefore()" />
<script>
function callAppendChild(){
var target = document.getElementById('target');
var li = document.createElement('li');
var text = document.createTextNode('JavaScript');
li.appendChild(text);
target.appendChild(li);
}
function callInsertBefore(){
var target = document.getElementById('target');
var li = document.createElement('li');
var text = document.createTextNode('jQuery');
li.appendChild(text);
target.insertBefore(li, target.firstChild);
}
</script>
append 추가한다
insertBefore 전에 추가한다 위치도 조정
.
<ul>
<li>HTML</li>
<li>CSS</li>
<li id="target">JavaScript</li>
</ul>
<input type="button" onclick="callRemoveChild();" value="removeChild()" />
<script>
function callRemoveChild(){
var target = document.getElementById('target');
target.parentNode.removeChild(target);
}
</script>
문제는 다불러오기가 힘들다 안에 안에 안을 불러와야한다
<ul>
<li>HTML</li>
<li>CSS</li>
<li id="target">JavaScript</li>
</ul>
<input type="button" onclick="callReplaceChild();" value="replaceChild()" />
<script>
function callReplaceChild(){
var a = document.createElement('a');
a.setAttribute('href', 'http://opentutorials.org/module/904/6701');
a.appendChild(document.createTextNode('Web browser JavaScript'));
var target = document.getElementById('target');
target.replaceChild(a,target.firstChild);
}
</script>
수정이 가능하다
'HTML 참고서 > HTML 생활코딩 Youtube' 카테고리의 다른 글
17.JavaScript Coding setInterval (0) | 2020.04.17 |
---|---|
16.JavaScript NodeText (0) | 2020.04.17 |
14. JavaScript Node (0) | 2020.04.16 |
13.JavaScript jQuery 조회범위 (0) | 2020.04.16 |
12.JavaScript API (0) | 2020.04.16 |