jQueryλ₯Ό μ°λ©΄ κ°λ¨νλ€.
//JavaScript > CSS μ‘°μ > inline style sheet
//κ° μ½κΈ°
alert($("#box").css("color")); //rgb(0, 0, 0)
$("#box").css("color", "blue"); // return #box κ°μ²΄
// κ°μ²΄ ννλ‘ μ¬λ¬ cssλ₯Ό μΈ μ μλ€.
$("#box").css({
color: "blue",
backgroundColor: "gold",
fontSize: "3rem",
});
// μΆκ°
//BOM
// box.className='one';
//DOM
// box.classList.add('one');
// box.classList.remove('two');
//jQuery
$("#box").addClass("one");
$("#box").addClass("two");
//μ κ±°
$("#box").removeClass("two");
$("#box").toggleClass("two");
console.log("width", $("#box").css("width"));
console.log("width", $("#box").css("height"));
$("#box").css("width", "300px");
console.log("width()", $("#box").width());
console.log("height()", $("#box").height());
$("#box").height(300);
console.log("innerWidth()", $("#box").innerWidth());
console.log("innerHeight()", $("#box").innerHeight());
console.log("outerWidth()", $("#box").outerWidth());
console.log("outerHeight()", $("#box").outerHeight());
console.log("outerWidth(true)", $("#box").outerWidth(true));
console.log("outerHeight(true)", $("#box").outerHeight(true));
μ½ν μΈ μ‘°μ
//text()
$("#box").text("νκΈΈλ"); // μ°κΈ°
alert($("#box").text()); //μ½κΈ°
//html()
$("#box").html("<b>μλ
νμΈμ.</b>");
alert($("#box").html());
//val()
$("#txt1").val("κΈ°λ³Έκ°");
alert($("#txt1").val());
HTML μμ± μ‘°μ
//BOM
//- obj.prop > μ½κΈ°
//- obj.prop = value; > μ°κΈ°
//DOM
//- obj.getAttribute('prop'); > μ½κΈ°
//- obj.setAttribute('prop', value); > μ°κΈ°
//*** attr(), prop() > λ§μλλ‘ μ¬μ© > λ¬Έμ λ°μ > μλ‘ κ΅μ²΄
//jQuery
//1. HTMLμ μμ±μ μ μ΄
// $("#txt1").attr("size", 50);
// alert($("#txt1").attr("size"));
//2. JavaScriptμ νλ‘νΌν°λ₯Ό μ μ΄
$("#txt1").prop("size", 50);
alert($("#txt1").prop("size"));
μ€ν¬λ‘€ μΈλμΌμ΄ν° λ° μμ±
$(document).scroll(function () {
// console.log($(document).scrollTop());
// λ¬Έμμ μΈλ‘κΈΈμ΄(μ€ν¬λ‘€λ° μ΅λ μμΉ) : 100%
// = μ€ν¬λ‘€λ° μμΉ : x
let x =
($(document).scrollTop() * 100) /
($(document).outerHeight() - $(window).outerHeight());
$("#bar").css("width", x + "%");
});
μ€ν¬λ‘€ μΈλμΌμ΄ν° λ° λͺ¨λννκΈ°