-
Notifications
You must be signed in to change notification settings - Fork 43
/
test.html
51 lines (36 loc) · 1.51 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
<!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.6.3.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() {
$.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>