-
Notifications
You must be signed in to change notification settings - Fork 35
/
dom.clone-and-other.html
121 lines (117 loc) · 4.99 KB
/
dom.clone-and-other.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Манипуляции с DOM: "clone()", "detach()", "empty()" и "destroy()"</title>
<link rel="profile" href="https://gmpg.org/xfn/11"/>
<link rel="shortcut icon" href="https://anton.shevchuk.name/favicon.ico"/>
<link rel="stylesheet" href="css/styles.css"/>
<style>
h1 {
cursor: pointer;
}
h1:hover {
color: #0059ff;
}
article#pinned:before {
content: '<article id="pinned" class="box important">'
}
article:not(#pinned):before {
content: '<article class="box">'
}
</style>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/code.js"></script>
<script>
$(function() {
$("h1")
.data("data", "Original data")
.click(function () {
output(
$(this).data("data")
)
})
})
</script>
</head>
<body class="formatter">
<header>
<h1>Манипуляции с DOM</h1>
<h2>Методы <code>clone()</code>, <code>detach()</code>, <code>empty()</code> и <code>destroy()</code></h2>
</header>
<main>
<article id="pinned" class="box important">
<h3>Article Title</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus rutrum,
lectus eu varius consectetur, libero velit hendrerit augue, ut posuere enim neque
in libero. Donec eget sagittis nibh. Suspendisse sed tincidunt urna. Cras quis
euismod neque. Maecenas auctor ultricies posuere. Pellentesque luctus pulvinar dui
eget semper. Donec sodales odio eu sapien varius luctus. Donec dictum feugiat diam
at malesuada. Sed nec massa in augue condimentum faucibus quis ut diam. Quisque
nisl sem, semper nec vulputate vel, mattis sit amet justo. Aliquam purus felis,
tempor at scelerisque quis, tincidunt in neque. Etiam ut risus diam. Pellentesque
fermentum risus id elit feugiat cursus. Ut fringilla dictum diam, sed iaculis
lorem pulvinar ut. Cras vel elit id velit commodo viverra sit amet vel orci.</p>
</article>
<article class="box">
<h3>Article Title</h3>
<p>Duis in vestibulum sem. Cras euismod tincidunt dui, et scelerisque tellus condimentum vel.
Maecenas et urna sit amet risus fermentum rhoncus nec porttitor ligula. Maecenas sit amet
turpis enim, ut iaculis est. Duis feugiat, lacus id placerat porttitor, lorem augue gravida
nisi, eu porta eros risus et lectus. Maecenas vestibulum nunc vel ipsum tincidunt sit amet
blandit sapien bibendum. Proin vel vulputate nisl. Duis tempor imperdiet placerat. Pellentesque
faucibus consequat magna, et bibendum nisl egestas non. Pellentesque sit amet mattis augue.
Aenean at diam tincidunt purus sollicitudin gravida non in nisi. Fusce bibendum, magna in
adipiscing mattis, sem risus fringilla mi, nec gravida lectus lectus at nibh. Suspendisse
adipiscing elementum laoreet. Suspendisse sem erat, varius quis aliquet vitae, dapibus sed
nibh. Nullam iaculis sem at mauris faucibus in vestibulum libero pretium. Aliquam eu turpis
libero. Fusce et ultrices lectus.</p>
</article>
</main>
<footer>
© <a href="https://anton.shevchuk.name/jquery-book/">jQuery for beginners</a>
</footer>
<aside>
<nav>
<a href="dom.wrap.html" title="go back" rel="prev">Back</a>
<a href="index.html#50" title="back to Index" rel="index">Index</a>
<a href="#" title="reload" onclick="window.location.reload();return false">Reload</a>
<a href="dom.html-and-text.html" title="go next" rel="next">Next</a>
</nav>
<hr/>
<code><em>// clone h1</em>
let $h1 = $(<span>"h1"</span>).clone()
<em>// change it</em>
$h1.prepend(<span>"A clone. "</span>)
<em>// paste a clone</em>
$(<span>"header"</span>).prepend($h1)</code>
<button type="button">Run Code</button>
<code><em>// clone h1 with data and events</em>
let $h1 = $(<span>"h1"</span>).clone(true)
<em>// change it</em>
$h1.prepend(<span>"A clone with data and events. "</span>)
<em>// paste a clone</em>
$(<span>"header"</span>).prepend($h1)</code>
<button type="button">Run Code</button>
<code><em>// detach h2</em>
let $h2 = $(<span>"h2"</span>).detach()
<em>// change it</em>
$h2.prepend(<span>"Detached. "</span>)
<em>// paste it</em>
$(<span>"main"</span>).prepend($h2)</code>
<button type="button">Run Code</button>
<code><em>// remove content</em>
$(<span>"p"</span>).empty()</code>
<button type="button">Run Code</button>
<code><em>// remove element</em>
$(<span>"p"</span>).remove()</code>
<button type="button">Run Code</button>
</aside>
<aside id="output">
<h4>Output:</h4>
<hr/>
<code></code>
</aside>
</body>
</html>