-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyQuery.js
More file actions
44 lines (43 loc) · 1.1 KB
/
myQuery.js
File metadata and controls
44 lines (43 loc) · 1.1 KB
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
var $ = function() {
var publicAPI = {
getByClass: function(selector) {
var type = selector[0];
if (!selector || type !== '.') {
return;
}
return document.getElementsByClassName(selector.substring(1));
},
getById: function(selector) {
var type = selector[0];
if (!selector || type !== '#') {
return;
}
return document.getElementById(selector.substring(1));
},
getByAttribute: function(selector) {
if (!selector) {
return;
}
return document.querySelector(selector);
},
ready: function(func) {
window.onload = func;
},
event: function(elem, type, handler) {
elem.addEventListener(type, function() {
handler();
});
}
};
return publicAPI;
}();
$.getById('#output').innerHTML = $.getById('#span1');
$.ready(function() {
console.log('hello world');
});
$.event($.getById('#span1'), 'click', function() {
alert('hello world');
});
// Current Code Written by Shako Kalandarishvili, Ideas by Nika and Shako
// Commits made by Nika
// Couldn't find the old version