제이쿼리 .add (selector)
제이쿼리 .add (selector)
설명 : 요소가 일치하는 요소 집합에 추가 된 새 jQuery 객체를 만듭니다.
1. tag 엘리먼트나 html tag를 직접 넣을 수 있습니다.
<div id="d1"></div>
div에 p태그를 넣고 싶다면
$("#d1").add("p");
이렇게 하면 p태그를 삽입할 수 있습니다.
또한
$("#d1").add("<p>~~~</p>");
이렇게 해도 됩니다.
예 :
모든 div를 찾고 테두리를 만듭니다. 그런 다음 모든 단락을 jQuery 객체에 추가하여 배경을 노란색으로 설정합니다.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>add demo</title>
<style>
div {
width: 60px;
height: 60px;
margin: 10px;
float: left;
}
p {
clear: left;
font-weight: bold;
font-size: 16px;
color: blue;
margin: 0 10px;
padding: 2px;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<p>Added this... (notice no border)</p>
<script>
$( "div" ).css( "border", "2px solid red" )
.add( "p" )
.css( "background", "yellow" );
</script>
</body>
</html>
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4586 | jQuery |
프로그래머7
|
8년 전 | 2088 | |
| 4585 | PHP | 8년 전 | 2159 | ||
| 4584 | PHP | 8년 전 | 2411 | ||
| 4583 | PHP | 8년 전 | 2354 | ||
| 4582 | jQuery |
프로그래머7
|
8년 전 | 1425 | |
| 4581 | jQuery |
프로그래머7
|
8년 전 | 1373 | |
| 4580 | jQuery |
프로그래머7
|
8년 전 | 1905 | |
| 4579 | PHP | 8년 전 | 2229 | ||
| 4578 | PHP | 8년 전 | 1740 | ||
| 4577 | PHP | 8년 전 | 2470 | ||
| 4576 | OS |
프로그래머7
|
8년 전 | 2697 | |
| 4575 | PHP | 8년 전 | 1924 | ||
| 4574 | PHP | 8년 전 | 1558 | ||
| 4573 | PHP | 8년 전 | 1966 | ||
| 4572 | PHP | 8년 전 | 2063 | ||
| 4571 | PHP | 8년 전 | 2415 | ||
| 4570 | PHP | 8년 전 | 2273 | ||
| 4569 | jQuery |
프로그래머7
|
8년 전 | 1863 | |
| 4568 | jQuery |
프로그래머7
|
8년 전 | 1402 | |
| 4567 | jQuery |
프로그래머7
|
8년 전 | 1967 | |
| 4566 | jQuery |
프로그래머7
|
8년 전 | 1897 | |
| 4565 | jQuery |
프로그래머7
|
8년 전 | 1648 | |
| 4564 | PHP | 8년 전 | 2578 | ||
| 4563 | PHP | 8년 전 | 1917 | ||
| 4562 | PHP | 8년 전 | 2426 | ||
| 4561 | jQuery |
프로그래머7
|
8년 전 | 1363 | |
| 4560 | jQuery |
프로그래머7
|
8년 전 | 1903 | |
| 4559 | jQuery |
프로그래머7
|
8년 전 | 1449 | |
| 4558 | node.js |
|
8년 전 | 3430 | |
| 4557 | jQuery |
프로그래머7
|
8년 전 | 1727 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기