<body>
<script>
function changeImage()
{
var txt1 = document.getElementById("txt1");
var img1 = document.getElementById("img1");
img1.src = txt1.value;
txt1.style.border = "10px solid #0000ff"; -> 문자열
}
</script>
<form>
<input id = "txt1" />
<input type ="button" onclick = "changeImage();" value="변경" />
<img id="img1" src="test.jpg" style="border:5px solid #ff0000;" />
</body>
// EX 5 : 엘리먼트 노드의 속성 CSS 속성 변경
window.addEventListener("load", function(){
var section5 = document.querySelector("#section5");
var srcInput = section5.querySelector(".src-input");
var imgSelect = section5.querySelector(".img-select");
var changeButton = section5.querySelector(".change-button");
var img = section5.querySelector(".img");
var colorInput = section5.querySelector(".color-input");
changeButton.onclick = function(){
img.src = "images/"+srcInput.value;
//img.src = "images/"+imgSelect.value;
//img.style.border-color = ?; -> 이런 식으로 사용할 수 없다.
//img.style["border-color"] = colorInput.value; 이런 식으로 사용할 수 있다.
img.style.borderColor = colorInput.value;
console.log(img.className);
};
출처 : 자바스크립트 DOM 프로그래밍 31강 - CSS 스타일 속성 변경
'JavaScript(JQUERY&JSON)' 카테고리의 다른 글
엘리먼트 노드 추가 (0) | 2019.12.13 |
---|---|
텍스트 노드를 동적으로 추가/삭제 (0) | 2019.12.12 |
Node 인터페이스 (0) | 2019.12.10 |
Selectors API (0) | 2019.12.09 |
코드분리와 이벤트 바인딩 방법 두 가지 (0) | 2019.11.15 |