JAVA/Jquery
Jquery addClass
왕왕왕왕
2015. 10. 2. 14:45
$(document).ready(function(){ $("button").click(function(){ $("p:nth-child(2)").addClass("intro"); }); });
버튼 클릭시 p태그중에 2번째 자식에게 intro 클래스명 부여
<style>
.intro {
font-size: 150%;
color: red;
}
</style>
intro 클래스는 폰트사이즈와 컬러 조정
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<p>This is another paragraph1111.</p>
p태그중에 2번째 자식이지만 h1태그까지 걸려서 This is a paragraph 텍스트가 조정된다.
p태그중에 2번째꺼로 하려면 nth-child(3)으로 해야 2번째 텍스트가 조정된다.