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:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user