$(선택자).함수명(매개변수);
선택자 = 선택하고 싶은 태그
<script>
var myJQ = jQuery("p"); //jQuey("p")가 담겨졌기 때문애 myJQ는 jQuery객체가 된다.
console.log(myJQ);
var elementP = document.getElementsByTagName("p");
console.log(elementP);
//myJQ와 elementP은 동일한 객체가 아니다. 데이터 타입 자체가 다르다.
//myJQ는 jQuery클래스로 객체가 생성되는 것이고, elementP는 element클래스(자바스크립트 클래스)로 객체가 생성되는 것이다.
</script>
<body>
<p>Hello jQuery!</p>
</body>
$(document).ready(function () {콜백함수()})
= 최상위 객체인 DOM객체(jQuery에서 제공하는) 를 불러와서 .ready()안의 함수를 실행시키는 명령.
$(function () {콜백함수()}
= document생략 가능. 위의 명령과 똑같은 기능.
📌Javascript : window.onload = jQuery : $(document).ready()
➡ 먼저 < body >를 메모리에 올림.
✔ window.onload
✔ $(document).ready()
<script>
//html() / text()
console.log("htmlMethod : " + $("#htmlMethod").html());
$("#htmlMethod").html("<strong>new</strong> " + $("#textMethod").html());
console.log("textMethod : " + $("#textMethod").text());
$("#textMethod").text("new " + $("#textMethod").text());
</script>
text()은 자식태그를 제외한 안의 문서(내용)만 출력하는 함수.
val()은 input태그에 정의된 value속성의 값을 확인하고자 할때 사용되는 함수.
$("#txt").val("변경내용");
val()함수안에 변경할 내용을 기술하면 value값이 변경된다.
<script>
//remove() // 문서 객체 제거
//empty() // 문서 객체 내부 제거
$("#removeMthod").remove(); //객체 태그 자체가 전부 제거 됨
$("#emptyMthod").empty(); //태그는 남아있고 안의 내용만 제거 됨
</script>