diff options
Diffstat (limited to 'assets/js/core/dom.js')
-rw-r--r-- | assets/js/core/dom.js | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/assets/js/core/dom.js b/assets/js/core/dom.js index 2c44de58..84bdade2 100644 --- a/assets/js/core/dom.js +++ b/assets/js/core/dom.js @@ -4,10 +4,12 @@ KB.dom = function (tag) { var element = typeof tag === 'string' ? document.createElement(tag) : tag; this.attr = function (attribute, value) { - if (value !== null) { + if (value !== null && typeof value !== 'undefined') { element.setAttribute(attribute, value); + return this; + } else { + return element.getAttribute(attribute); } - return this; }; this.data = function (attribute, value) { @@ -175,3 +177,15 @@ KB.find = function (selector) { return null; }; + +KB.exists = function (selector) { + return !!document.querySelector(selector); +}; + +KB.focus = function (selector) { + var element = document.querySelector(selector); + + if (element) { + return element.focus(); + } +}; |