저번 페이지에서 내용 및 속성 가져오기를 배웠는데,
이번 페이지에서는 설정을 해보겠습니다.
함수명은 같지만, 매개변수를 줍니다.
콘텐츠 설정 - text(), html(), val()
1
2
3
4
5
6
7
8
9 |
$("#btn1").click(function(){
$("#test1").text("Hello world!");
});
$("#btn2").click(function(){
$("#test2").html("<b>Hello world!</b>");
});
$("#btn3").click(function(){
$("#test3").val("Dolly Duck");
}); |
cs |
콜백 함수도 함께 제공됩니다.
콜백 함수에는 선택된 요소 목록의 현재 요소와 이전 값의 두 매개 변수가 있습니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
$("#btn1").click(function(){
$("#test1").text(function(i, origText){
return "Old text: " + origText + " New text: Hello world!
(index: " + i + ")";
});
});
$("#btn2").click(function(){
$("#test2").html(function(i, origText){
return "Old html: " + origText + " New html: Hello <b>world!</b>
(index: " + i + ")";
});
});
|
cs |
속성 설정 - attr()
attr() - 메소드는 속성 값을 설정 / 변경하는데도 사용됩니다.
1
2
3 |
$("button").click(function(){
$("#w3s").attr("href", "https://www.w3schools.com/jquery");
}); |
cs |
출처:https://www.w3schools.com/jquery/
'똥 싸기 > jQuery' 카테고리의 다른 글
[jQuery]요소 제거 (0) | 2017.09.19 |
---|---|
[jQuery]요소 추가 (0) | 2017.09.19 |
[jQuery]내용 및 속성 가져오기 (0) | 2017.09.19 |
[jQuery]체인 (0) | 2017.09.19 |
[jQuery]애니메이션 (0) | 2017.09.13 |