Wait for an element(s) with a specific selector to appear
waitForSelector(selector, cb[, options])Type: String | Array
Css selector or an array of selectors
Type: Function
Callback function
Type: Element
Default: document.body
Type: Boolean
Default: false
Sometimes elements can be appended, removed and appended again. This option allows you to track each append of an element into the DOM structure.
Type: Boolean
Default: false
Wait until one of the given selectros appears in DOM
Type: Number
Default: 0
Stop waiting after this amount of milliseconds.
Calls cb function with no arguments. Turned off by default.
Returns stop method
// Single
waitForSelector('.block3', (elem) => {
// => <div class="block3"></div>
})
// Multiple
waitForSelector(['.block1', '.block2', '.block4', '.block8'], (list) => {
// => ['.block4', '.block2', '.block8', '.block1']
})
// Race
waitForSelector(['.block7', '.block4', '.block5', '.block4'], (elem) => {
// => <div class="block5"></div>
}, { race: true })- moved from
setIntervaltoMutationObserver
delayoption renamed tointerval- added
timeoutoption