-
Notifications
You must be signed in to change notification settings - Fork 2
/
dataset.html
69 lines (55 loc) · 2.03 KB
/
dataset.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>dataset</title>
</head>
<body>
<ul>
<li class="person" data-twitter="jdsharp" data-site="http://jdsharp.com" data-hometown="Omaha, NE">Jonathan Sharp</li>
</ul>
<div data-long-attribute="hello world"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script src="jquery.dataset.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
if ( !console || !console.log ) {
console = {
log : function() {},
dir : function() {}
};
}
console.dir( $('li').dataset() );
// Bind to the dataset event for the whole document
$(document).bind('dataset', function(evt, dataset) {
console.log('dataset event:');
console.dir(dataset);
});
// Set a key/value
$('li').dataset('twitter', 'jqueryminute');
// Update a hash
$('li').dataset({ name: 'Jonathan D. Sharp', site: 'http://jdsharp.com' });
// Dump our dataset again
console.dir( $('li').dataset() );
// Verify we can read a single element
var twitter = $('li').dataset('twitter');
alert('Twitter handle is: ' + twitter);
// Make sure the dataset event is triggered/captured
$('body').dataset('url', 'http://jquery.com');
// Dump our dataset again
console.dir( $('div').dataset() );
$('div').dataset('longAttribute', '123');
console.dir( $('div').dataset() );
$.dataset.dashTransform = false;
$('div').dataset('long-attribute', '456');
console.dir( $('div').dataset() );
console.log( 'Long attribute: ' + $('div').dataset('longAttribute') );
$('div').removeDataset('long-attribute');
$('div').dataset({ abc: '123', def: '456' });
console.dir( $('div').dataset() );
$('div').removeDataset('*');
console.dir( $('div').dataset() );
});
</script>
</body>
</html>