forked from pie6k/jquery.initialize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
56 lines (40 loc) · 1.7 KB
/
test.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery.initialize test</title>
<!-- Load MutationObserver and WeakMap polyfill for IE9 and 10 -->
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="jquery.initialize.js"></script>
</head>
<body>
<h2>We want every .initialize-me item to have color changed to blue by js - no matter how and when item with this class is added</h2>
<button id="add-new">Add new item</button>
<button id="change-class">Just add .initialize-me to .wrong-class</button>
<hr>
<div class="wrong-class">
This elem has .wrong-class and will not be initialized.
</div>
<div class="initialize-me">
This class has .initialize-me class so it will be initialized.
</div>
<p>You can even add item with .initialize-me class via browser inspector - proper js will be executed on it just when you finish edition.</p>
<script>
$(function() {
// Deprecated API (does not work with jQuery >= 3.1.1):
// $('.initialize-me').initialize(function() {
// $(this).css('color', 'blue');
// });
$.initialize('.initialize-me', function() {
$(this).css('color', 'blue');
});
$('#add-new').click(function(){
$('<div>').addClass('initialize-me').text('New item that was just appended to body and it’s color is automatically changed to blue without any additional js.').appendTo('body');
});
$('#change-class').click(function(){
$('.wrong-class').addClass('initialize-me');
});
});
</script>
</body>
</html>