diff options
author | Johann-S <johann.servoire@gmail.com> | 2018-08-07 19:37:46 +0300 |
---|---|---|
committer | Johann-S <johann.servoire@gmail.com> | 2018-08-07 19:49:02 +0300 |
commit | 6b92321f6a04f07e0a3531d0e546c3cc20867bdb (patch) | |
tree | e4abe9eca0f9718d066eb19dee499840292981fa /js/src/util.js | |
parent | ae53690ab4fbc044f69120f4d495137a79cdca32 (diff) |
fix(util): use getElementById when it's possible
Diffstat (limited to 'js/src/util.js')
-rw-r--r-- | js/src/util.js | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/js/src/util.js b/js/src/util.js index eb98d449c8..3008c22785 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -77,12 +77,20 @@ const Util = (($) => { getSelectorFromElement(element) { let selector = element.getAttribute('data-target') + let method = 'querySelector' + if (!selector || selector === '#') { - selector = element.getAttribute('href') || '' + selector = (element.getAttribute('href') || '').trim() + } + + const validSelector = selector + if (selector.charAt(0) === '#') { + selector = selector.substr(1) + method = 'getElementById' } try { - return document.querySelector(selector) ? selector : null + return document[method](selector) ? validSelector : null } catch (err) { return null } |