mirror of
https://github.com/chylex/Discord-History-Tracker.git
synced 2025-04-13 07:17:12 +03:00
Add a smaller version of dom.js to renderer
This commit is contained in:
parent
7f654eaf5d
commit
679a2d8532
40
src/renderer/scr.dom.js
Normal file
40
src/renderer/scr.dom.js
Normal file
@ -0,0 +1,40 @@
|
||||
var DOM = (function(){
|
||||
return {
|
||||
/*
|
||||
* Returns a child element by its ID. Parent defaults to the entire document.
|
||||
*/
|
||||
id: function(id, parent){
|
||||
return (parent || document).getElementById(id);
|
||||
},
|
||||
|
||||
/*
|
||||
* Returns an array of all child elements containing the specified class. Parent defaults to the entire document.
|
||||
*/
|
||||
cls: function(cls, parent){
|
||||
return Array.prototype.slice.call((parent || document).getElementsByClassName(cls));
|
||||
},
|
||||
|
||||
/*
|
||||
* Returns an array of all child elements that have the specified tag. Parent defaults to the entire document.
|
||||
*/
|
||||
tag: function(tag, parent){
|
||||
return Array.prototype.slice.call((parent || document).getElementsByTagName(tag));
|
||||
},
|
||||
|
||||
/*
|
||||
* Creates an element, adds it to the DOM, and returns it.
|
||||
*/
|
||||
createElement: function(tag, parent){
|
||||
var ele = document.createElement(tag);
|
||||
parent.appendChild(ele);
|
||||
return ele;
|
||||
},
|
||||
|
||||
/*
|
||||
* Removes an element from the DOM.
|
||||
*/
|
||||
removeElement: function(ele){
|
||||
ele.parentNode.removeChild(ele);
|
||||
}
|
||||
};
|
||||
})();
|
Loading…
x
Reference in New Issue
Block a user