JQuery란 덜 작성하고 더 많은 작업을 수행하는 자바스크립트 라이브러리이다.
많은 줄의 자바스크립트를 단 한줄의 코드로 호출할 수 있는 메서드로 묶는다.
W3school의 연습문제를 참고하여 정리했다.
https://www.w3schools.com/jquery/exercise_jq.asp?filename=exercise_jq_selectors1
$("#test").hide();
$("*").hide();
$("[href]").hide();
$(tr:odd).hide();
$(tr:even).hide();
$("p").click(function(){
$(this).hide();
});
$("p").dblclcik(function(){
$(this).hide();
});
$("p").mouseenter(function(){
$(this).hide();
});
$("input").keypress(function(){
$(this).hide();
});
$("p").on("click", function(){
$(this).hide();
});
$(document).on("click", ".dynamic-element", function(){
// 동적 요소 클릭 시 실행될 코드
})
$(#"myElement").on("click dblclick", function(event) {
if(event.type ==="click") {
// 클릭 시 실행될 코드
} else if (event.type === "dblclick") {
// 더블클릭 시 실행될 코드
}
});
$("#myElement").on("click", function(){
// 클릭 시 실행될 코드
});
// 나중에 이벤트 핸들러 제거
$("#myElelment").off("click");
$("p").click(function(){
$(this).fadeOut("slow");
});
$("div").fadeTo("slow",0.2);
$("button").click(function(){
$("div").fadeToggle(1000);
});
$("div").slideUp();
$("div").slideDown();
$("button").click(function(){
$("div").slideToggle();
});
$("div").animate({left : 250px});
$("div").text();
$("div").html();
$("div").val();
$("a").attr("href");
$("div").text("Hellow World");
$("input").val("John Doe");
$("img").attr("src", "myimage.jpg");
$("#myLink").text("Demo");
$("#myLink").attr("href", "https://www.demo.com");
$("p").append("Yes!");
$("p").prepend("Yes!");
$("div").remove();
$("div").empty();
$("div").remove(".test, .demo");
$("p").addClass("important");
$("p").addClass("important test");
$("p").toggleClass("important");
$("p").css("background-color", "pink");
$("p").css("background-color","5px dotted red");
$("p").css("background-color");
$("p").css({"color":"white", "font-size" : "25px", "padding":"15px"});
$("div").height(500).width(500);
$("div").height();
$("div").innerHeight();
$("div").outerHeight();
$("div").outerHeight(true);
$("span").parent();
$("span").parents();
$("span").children();
$("div").find("span");
$("h2").sibilings();
$("div").first();