Closed ollyollyollyltd closed 5 years ago
Should note - as a workaround (as demonstrated in the fiddle) you can still safely attach events to the 'original' object without chaining them:
const $el = $('#iDontExist');
$el.slider() // returns undefined
$el.on('slide', handleSlide);
// Works fine, whether or not `#iDontExist` is present in DOM.
$('#iDontExist').slider().on('slide', handleSlide);
// Breaks if `#iDontExist` is not present in DOM as slider() will return undefined.
Upon investigation this may be an error with Bridget
implementation in bootstrap-slider
.
I'm not sure how you handle this dependency as it is bundled into the main src/bootstrap-slider.js
file. I've created a pull request which fixes the issue: https://github.com/seiyria/bootstrap-slider/pull/917
Issue fixed. Closing.
Fiddle: https://jsfiddle.net/aduw6L0p/
Bootstrap Slider v10.6.1 Jquery v3.3.1 Tested using Chrome v72
Description If you call
slider()
on a jQuery object which has matched no elements, it will returnundefined
which will break chaining.Steps to reproduce
slider()
on a jQuery object which contains no elementsExpected behaviour The return value should be an empty jQuery object, the same as if you had called
$()
. This would allow safe chaining with further jQuery functions such ason()
regardless of whether the element has been matched or not.Actual behaviour The return value is
undefined
and calling other jQuery functions will throw an error. The original object is unchanged (i.e. what you called.slider()
on is unchanged.