1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-15 10:05:40 +02:00

add information about valid selectors (#27137)

This commit is contained in:
Johann-S
2018-08-31 21:00:29 +02:00
committed by GitHub
parent 54d86e6249
commit a3e45d8ced
3 changed files with 5 additions and 35 deletions

View File

@@ -77,20 +77,13 @@ const Util = (($) => {
getSelectorFromElement(element) {
let selector = element.getAttribute('data-target')
let method = 'querySelector'
if (!selector || selector === '#') {
selector = (element.getAttribute('href') || '').trim()
}
const validSelector = selector
if (selector.charAt(0) === '#' && selector.indexOf(',') === -1) {
selector = selector.substr(1)
method = 'getElementById'
}
try {
return document[method](selector) ? validSelector : null
return document.querySelector(selector) ? selector : null
} catch (err) {
return null
}