-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathattributes.html
65 lines (58 loc) · 1.47 KB
/
attributes.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
<!doctype html>
<html>
<head>
<title>Attributes Order</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>body { font-family: sans-serif; }</style>
<script>
this.onload = function () {
var p = document.querySelector('p');
var input = p.querySelector('input');
var errors = [];
try {
assert(p, 'data-x,class');
} catch(e) {
errors.push(e.message);
}
try {
assert(input, 'class,value,onblur,onkeypress,onkeydown');
} catch(e) {
errors.push(e.message);
}
if (errors.length) alert(errors.join('\n'));
function assert(el, expected) {
var attrs = attributes(el);
if (attrs.join(',') !== expected)
throw new Error(
'unexpected attributes order for node ' +
el.nodeName +
'\n' +
attrs.join('\n')
);
}
function attributes(el) {
for (var
out = [],
attr = el.attributes,
i = 0, length = attr.length;
i < length; i++
)
out[i] = attr[i].name;
return out;
}
};
</script>
</head>
<body>
<p data-x="" class="">
some content, also an input.
<input
class="class"
value="value"
onblur="console.log('onblur')"
onkeypress="console.log('onkeypress')"
onkeydown="console.log('onkeydown')"
>
</p>
</body>
</html>