๐ป
JavaScript ์ ์ดํด - [jQuery] DOM ํจ์(2) ๋ณธ๋ฌธ
https://api.jquery.com/category/traversing/
07.DOM.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery - DOM ํ์ ๋ฉ์๋</title>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript">
//๋์, ํ, ๋ชจ๋ ๋์, ๋ชจ๋ ํ, ๋ชจ๋ ํ์
$(function(){
$('#coffee').next().css('color', 'pink');
$('#coffee').prev().css('color', 'pink');
$('#strawberry').nextAll().css('color', 'red');
$('#strawberry').prevAll().css('color', 'blue');
$('#citrus').sblings().css('color', 'yellow');
$('#citrus').sblings('#tomato').css('fontSize','20px');
});
</script>
</head>
<body>
<h3>๋งํค์๋</h3>
<h3>์๋ฉ๋ฆฌ์นด๋
ธ</h3>
<h3 id="coffee" style="color:blue">์นดํธ์น๋
ธ</h3>
<h3>๊นํ๋ผ๋ผ</h3>
<h3>๋ชจ์นด</h3>
<br/><br/><br/>
<div id="first">
<div>์ฌ๊ณผ</div>
<div>๋ฐ๋๋</div>
<div id="strawberry">๋ธ๊ธฐ</div>
<div>์๋ฐ</div>
<div id="melon">๋ฉ๋ก </div>
</div>
<br/><br/><br/>
<div id="second">
<div>ํฌ๋</div>
<div id="citrus">๊ทค</div>
<div>๋ฉ๋ก </div>
<div id="tomato">ํ ๋งํ </div>
</div>
</body>
</html>
08.DOM.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery - DOM ํ์ ๋ฉ์๋</title>
</head>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript">
$(function(){
var arr = new Array();
//๋ถ๋ชจ
$('#melon').parent().each(function(i, e){
//arr.push(i + " " + e.tagName + " " + $(e).text());
});
//์กฐ์
//0 DIV 1 DIV 2 BODY 3 HTML
$('#melon').parents().each(function(i, e){
arr.push(i + " " + e.tagName);
});
alert(arr.join("\n"));
});
</script>
<body>
<div id="first">
<span>์ฌ๊ณผ</span>
<span>๋ฐ๋๋</span>
<span id="strawberry">๋ธ๊ธฐ</span>
<div>
<span>์๋ฐ</span>
<span id="melon">๋ฉ๋ก </span>
</div>
<div>์๋ฉ๋ฆฌ์นด๋
ธ ์ปคํผ</div>
</div>
</body>
</html>
09.DOM.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jQuery - DOM ํํฐ ๋ฉ์๋</title>
</head>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript">
$(function(){
//$('#main p:first') $('.middle > p.first')
$('#main p').first().css('color', 'pink');
$('#main').children('div').first().css('color', 'blue');
$('#main p').last().css('color', 'red');
$('#main p').eq(2).css('color', 'yellow');
$('#main p').find('p').eq(3).css('color', 'green');
});
</script>
<body>
<div id="main">
<div class="middle">DIV</div>
<p>์ฌ๊ณผ</p>
<p>๋ฐ๋๋</p>
<p>๋ธ๊ธฐ</p>
<p>๋ฉ๋ก </p>
<div id="sub">
<p>์๋ฉ๋ฆฌ์นด๋
ธ</p>
</div>
</div>
</body>
</html>
๋ฐ์ํ
'KITRI > JAVASCRIPT' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
JavaScript ์ ์ดํด - [jQuery] Effects : Hide, Toggle, Slide, Fade (0) | 2020.07.22 |
---|---|
JavaScript ์ ์ดํด - [jQuery] Theme (0) | 2020.07.22 |
JavaScript ์ ์ดํด - [jQuery] DOM ํจ์(1) (0) | 2020.07.21 |
JavaScript ์ ์ดํด - [jQuery] Selector(2) : ํํฐ (0) | 2020.07.21 |
JavaScript ์ ์ดํด - [jQuery] Selector(1) : ๊ธฐ๋ณธ, ์์(์์/ํ์ ) (0) | 2020.07.20 |
Comments