해당 포스팅에서는 jQuery 기본 문법에 대해 정리해 보고자 한다.
$("p")
$(#id")
$(".class")
| Mouse Events | Keyboard Events | Form Events | Document/Window Events |
|---|---|---|---|
| click | keypress | submit | load |
| mouseenter | keyup | focus | scroll |
| mouseleave | blur | upload |
$("p").click(function(){
$(this).hide();
});
$("#p1").mouseenter(function(){
alert("You entered p1!");
});
$("#p1").hover(function(){
alert("You entered p1!");
},
function(){
alert("Bye! You now leave p1!");
});
$("p").on({
hover: function() {
$(this).css("background-color", "red");
},
click: function() {
$(this).css("background-color", "black");
}
});
$("#hide").click(function(){
$("p").hide();
});
$("#show").click(function(){
$("p").show();
});
$("button").click(function(){
$("p").toggle();
});
$("button").click(function(){
$("#div1").fadeIn();
$("#div2").fadeIn("slow");
$("#div3").fadeIn(3000);
});
$("#flip").click(function(){
$("#panel").slideDown();
});
DOM 조작을 위한 간단하지만 유용한 세 가지 jQuery 메서드는 다음과 같습니다.
$("#btn1").click(function(){
alert("Text: " + $("#test").text());
});
$("#btn2").click(function(){
alert("HTML: " + $("#test").html());
});
jQuery attr()메서드는 속성 값을 가져오는 데 사용됩니다.
$("button").click(function(){
alert($("#w3s").attr("href"));
});
새 콘텐츠를 추가하는 데 사용되는 4가지 jQuery 메서드를 살펴보겠습니다.
요소와 콘텐츠를 제거하기 위해 주로 두 가지 jQuery 메서드가 있습니다.
참조
https://velog.io/@sanna422/jQuery-%EB%AC%B8%EB%B2%95-%EC%A0%95%EB%A6%AC-%EB%B0%8F-%EC%8B%A4%EC%8A%B5