-
Notifications
You must be signed in to change notification settings - Fork 35
/
data.html
87 lines (86 loc) · 4 KB
/
data.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
<!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>Работа с методом "data()"</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"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/code.js"></script>
</head>
<body>
<header>
<h1>Работа с методом <code>data()</code></h1>
<p>Cобытия <del>setData()</del>, <del>getData()</del>, и <del>changeData()</del> устарели с версии 1.8, и удалены в 1.9</p>
</header>
<main>
<article>
<p data-question="Главный вопрос жизни, Вселенной и всего такого">
<span class="text-sky-700"><p data-question="Главный вопрос жизни, Вселенной и всего такого"></span>
<br/>
<br/>
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.
<br/>
<br/>
<span class="text-sky-700"></p></span>
</p>
</article>
</main>
<footer>
© <a href="https://anton.shevchuk.name/jquery-book/">jQuery for beginners</a>
</footer>
<aside>
<nav>
<a href="offset-and-position.html" title="go prev" rel="prev">Prev</a>
<a href="index.html#20" title="back to Index" rel="index">Index</a>
<a href="#" title="reload" onclick="window.location.reload();return false">Reload</a>
</nav>
<hr/>
<div>
<code data-append="#output"><em>// data attribute or data-object</em>
$(<span>'p'</span>).data(<span>'question'</span>)</code>
<button type="button">Run Code</button>
<code data-append="#output"><em>// attribute without changes</em>
$(<span>'p'</span>).attr(<span>'data-question'</span>)</code>
<button type="button">Run Code</button>
<code data-append="#output"><em>// data attribute or data-object</em>
$(<span>'p'</span>).data(<span>'answer'</span>)</code>
<button type="button">Run Code</button>
<code data-append="#output"><em>// attribute without changes</em>
$(<span>'p'</span>).attr(<span>'data-answer'</span>)</code>
<button type="button">Run Code</button>
<code contenteditable="true"><em>// just number</em>
$(<span>'p'</span>).data(<span>'answer'</span>, 42)</code>
<button type="button">Run Code</button>
<code contenteditable="true"><em>// or object</em>
$(<span>'p'</span>).data(
<span>'answer'</span>,
{ <span>"key"</span>: <span>"value"</span>}
)</code>
<button type="button">Run Code</button>
<code data-append="#output"><em>// alternative way</em>
$.data($(<span>'p'</span>).get(0), <span>'answer'</span>)</code>
<button type="button">Run Code</button>
<code><em>// remove data from data-object</em>
$(<span>'p'</span>).removeData(<span>'answer'</span>)</code>
<button type="button">Run Code</button>
</div>
</aside>
<aside id="output">
<h4>Output:</h4>
<hr/>
<code></code>
</aside>
</body>
</html>