Web/jquery
[jQuery] jQuery css 변경하는 방법 (여러개 예제)
eunyoe
2023. 3. 16. 10:32
반응형
안녕하세요. 오늘은 버튼을 클릭했을때 div의 style이 변경되는 방법에 대해 알아보겠습니다.
그리고 jquery로 css를 하나씩 바꿀 때, 여러개 바꾸는 방법에 대해 알려드리겠습니다.
style 속성 하나씩 바꿀때
$(div).css("background-color","yellow");
style 속성 여러개 바꿀때
$('div')css({"background-color":"yellow","width":"100px"});
jquery로 css를 여러개 변경할 때는 ({})안에 속성을 넣어주시면 됩니다.
다음은 버튼을 클릭할 때, div style이 바뀌는 간단한 예제입니다.
html
<button>클릭</button>
<div></div>
[css]
div{width: 200px;height: 200px;background: red;}
[js]
$('button').click(function(){
$('div').css({'background':'yellow','width':'100px'})
});
반응형