<!DOCTYPE html> <htmllang="en"> <head> <metacharset="UTF-8" /> <metaname="viewport"content="width=device-width, initial-scale=1.0" /> <metahttp-equiv="X-UA-Compatible"content="ie=edge" /> <title>Simple html</title> <style> .callout { border: 1px solid #ff0080; margin: 2px 4px; padding: 2px 6px; } .code { background: #ccc; margin: 1px 2px; padding: 1px 4px; font-family: monospace; } </style> </head> <body> <header> <h1>Simple Html</h1> </header> <divid="content"> <p>This is a <i>simple</i> HTML file.</p> <divclass="callout"> <p>this is as fancy as...we'll get!</p> </div> <p> IDs (such as <spanclass="code">#content</span>) are unique (there can only be one per page). </p> <p> Classes (such as <span>.callout</span>) can be used on many elements </p> <divid="callout2"class="callout fancy"> <p>A single HTML element can have multiple classes</p> </div> </div> </body> </html>
제이쿼리에서는 요소의 스타일도 쉽게 변경 가능 addClass() : 클래스 추가 removeClass() : 클래스 제거 toggleClass() : 클래스 토글 filter() : 셋 요소 일치 선택자에 맞는 요소만 남도록 선택범위축소 not() : filter()의 반대 find() : 주어진 선택자에 일치하는 자손만 남김
1 2 3 4 5 6 7 8
//홀수 문단만 빨간색으로 $("p:odd").css("color", "red"); //p태그뒤에 hr을 넣고 p태그 안에 각주를 넣고 홀수번째 p태그에 텍스트 빨간색 $("p") .after("<hr/>") .append("<sup>*</sup>") .filter(":odd") .css("color", "red");
19.6 제이쿼리 취소
get(): 제이쿼리 객체로 감싼 것을 취소하고 dom 요소에 직접 접근하기 위해서는 get 메서드를 사용해야 한다.