Skip to content

Commit d6e36bd

Browse files
committed
Added selector support for "set"
1 parent 7ca6788 commit d6e36bd

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/slideshow.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ function Slideshow({container = '#slideshow', slideshowSelector = '.slideshow',
296296
/**
297297
* Sets the current slide.
298298
*
299-
* @param {number|HTMLElement|Node} slide Index of the element or the
299+
* @param {string|number|HTMLElement|Node} slide Index of the element or the
300300
* element itself to bet setted as
301301
* current.
302302
*
@@ -311,7 +311,11 @@ function Slideshow({container = '#slideshow', slideshowSelector = '.slideshow',
311311
*/
312312
this.set = (slide) => {
313313
if (slide == null) {
314-
throw new Error('The given element is not a valid value. Please, insert an integer or a DOM element.');
314+
throw new Error('The given element is not a valid value. Please, insert a string, an integer or a DOM element.');
315+
}
316+
317+
if (typeof slide === 'string') {
318+
slide = document.querySelector(slide);
315319
}
316320

317321
if (typeof slide === 'number') {
@@ -332,7 +336,7 @@ function Slideshow({container = '#slideshow', slideshowSelector = '.slideshow',
332336
}
333337
}
334338
else {
335-
throw new Error('The given element is not a valid value. Please, insert an integer or a DOM element.');
339+
throw new Error('The given element is not a valid value. Please, insert a string, an integer or a DOM element.');
336340
}
337341

338342
const oldCurrent = current;

0 commit comments

Comments
 (0)