IT 관련/Html5
JavaScript와 CSS의 만남1 (객체의 색상 변경)
과정에서 오는 행복
2011. 10. 7. 20:47
[li태그를 추출하여 글자색을 변경함]
<head>
<script type="text/javascript">
function test2() {var li = document.getElementsByTagName('li');
for(var i = 0; i<li.length; i++) {
li[i].style.color = '#f00';
}
}
window.onload = test2;
<body>
<h1 style="color:#f00">Introduction</h1>
<p style="color:#00f; font-size:13pt">there are number of reasons</p>
<p style="color:#0f0">두번째 단락</p>
<ul>
<li id='test1'>I can found every where</li>
<li>number2</li>
<li>number3</li>
</ul>
</body>
----------------------------------------------------------------------------
자바스크립트에의 getElementsByTagName을 이용하여, 해당 태그를 배열로 가져오고 색을 변경함
반응형