1 2 3 4 5 6 7 8 9 10 | < ul > < li id = "target" >html</ li > < li >css</ li > < li >JavaScript</ li > </ ul > < script > var t = document.getElementById('target').firstChild; console.log(t.nodeValue); console.log(t.data); </ script > |
<!DOCTYPE html>
<
html
>
<
head
>
<
style
>
#target{
font-size:77px;
font-family: georgia;
border-bottom:1px solid black;
padding-bottom:10px;
}
p{
margin:5px;
}
</
style
>
</
head
>
<
body
>
<
p
id
=
"target"
>Cording everybody!</
p
>
<
p
> data : <
input
type
=
"text"
id
=
"datasource"
value
=
"JavaScript"
/></
p
>
<
p
> start :<
input
type
=
"text"
id
=
"start"
value
=
"5"
/></
p
>
<
p
> end : <
input
type
=
"text"
id
=
"end"
value
=
"5"
/></
p
>
<
p
><
input
type
=
"button"
value
=
"appendData(data)"
onclick
=
"callAppendData()"
/>
<
input
type
=
"button"
value
=
"deleteData(start,end)"
onclick
=
"callDeleteData()"
/>
<
input
type
=
"button"
value
=
"insertData(start,data)"
onclick
=
"callInsertData()"
/>
<
input
type
=
"button"
value
=
"replaceData(start,end,data)"
onclick
=
"callReplaceData()"
/>
<
input
type
=
"button"
value
=
"substringData(start,end)"
onclick
=
"callSubstringData()"
/></
p
>
<
script
>
var target = document.getElementById('target').firstChild;
var data = document.getElementById('datasource');
var start = document.getElementById('start');
var end = document.getElementById('end');
function callAppendData(){
target.appendData(data.value);
}
function callDeleteData(){
target.deleteData(start.value, end.value);
}
function callInsertData(){
target.insertData(start.value, data.value);
}
function callReplaceData(){
target.replaceData(start.value, end.value, data.value);
}
function callSubstringData(){
alert(target.substringData(start.value, end.value));
}
</
script
>
</
body
>
</
html
>
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 | < style > body{ padding:0; margin:0; } div{ border:50px solid #1065e6; padding:50px; margin:50px; } #target{ width:100px; height:2000px; } </ style > < div > < div id = "target" > Coding </ div > </ div > < script > var t = document.getElementById('target'); setInterval(function(){ console.log('getBoundingClientRect : ', t.getBoundingClientRect().top, 'pageYOffset:', window.pageYOffset); }, 1000) </ script > |
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 | < style > body{ padding:0; margin:0; } div{ border:50px solid #1065e6; padding:50px; margin:50px; } #target{ width:100px; height:2000px; } </ style > < input type = "button" id = "scrollBtn" value = "scroll(0, 1000)" /> < script > document.getElementById('scrollBtn').addEventListener('click', function(){ window.scrollTo(0, 1000); }) </ script > < div > < div id = "target" > Coding </ div > </ div > |
'스터디 > 자바스크립트 완벽 가이드 정리' 카테고리의 다른 글
Node 객체에 대하여(NODE 객체와 NODE객체 컨트롤하기) (0) | 2017.12.03 |
---|---|
이벤트 및 우클릭 방지 (0) | 2017.11.28 |
5판 7장 객체(Object)와 배열(Array) (0) | 2017.11.13 |