Notice
Recent Posts
Recent Comments
Link
«   2024/11   »
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
Tags
more
Archives
Today
Total
관리 메뉴

재훈재훈

getElementById() 본문

Computer Engineering/JavaScript

getElementById()

jaehoonx2 2018. 11. 16. 11:53

getElementById('ID').function


html 문서 내의 id element(ID)에 접근하여 특정 동작(function)을 취하게 하는 JS function




Src


<!DOCTYPE html>

<html>

<body>

<h1>What Can JavaScript Do?</h1>

<p>JavaScript can change HTML attributes.</p>

<p>In this case JavaScript changes the src (source) attribute of an image.</p>


<button onclick="document.getElementById('myImage').src='pic_bulbon.gif'">Turn on the light</button>


<img id="myImage" src="pic_bulboff.gif" style="width:100px">


<button onclick="document.getElementById('myImage').src='pic_bulboff.gif'">Turn off the light</button>

</body>

</html>




ScreenShot



'Computer Engineering > JavaScript' 카테고리의 다른 글

this  (0) 2018.05.15
상속  (0) 2018.04.07
constructor 프로퍼티  (0) 2018.04.07
prototype 프로퍼티  (0) 2018.04.07
클로저  (0) 2018.04.07