{"record":{"id":"269e2b56de6fdcf0","repo":"apache/hadoop","slug":"selector-option-must-be-specified-when-initializ","errorCode":null,"errorMessage":"`selector` option must be specified when initializing {} on the window.document object!","messagePattern":"`selector` option must be specified when initializing (.+?) on the window\\.document object!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/static/bootstrap-3.4.1/js/bootstrap.js","lineNumber":1476,"sourceCode":"    viewport: {\n      selector: 'body',\n      padding: 0\n    },\n    sanitize : true,\n    sanitizeFn : null,\n    whiteList : DefaultWhitelist\n  }\n\n  Tooltip.prototype.init = function (type, element, options) {\n    this.enabled   = true\n    this.type      = type\n    this.$element  = $(element)\n    this.options   = this.getOptions(options)\n    this.$viewport = this.options.viewport && $(document).find($.isFunction(this.options.viewport) ? this.options.viewport.call(this, this.$element) : (this.options.viewport.selector || this.options.viewport))\n    this.inState   = { click: false, hover: false, focus: false }\n\n    if (this.$element[0] instanceof document.constructor && !this.options.selector) {\n      throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!')\n    }\n\n    var triggers = this.options.trigger.split(' ')\n\n    for (var i = triggers.length; i--;) {\n      var trigger = triggers[i]\n\n      if (trigger == 'click') {\n        this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))\n      } else if (trigger != 'manual') {\n        var eventIn  = trigger == 'hover' ? 'mouseenter' : 'focusin'\n        var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'\n\n        this.$element.on(eventIn  + '.' + this.type, this.options.selector, $.proxy(this.enter, this))\n        this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))\n      }\n    }\n","sourceCodeStart":1458,"sourceCodeEnd":1494,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/static/bootstrap-3.4.1/js/bootstrap.js#L1458-L1494","documentation":"Tooltip.prototype.init throws when a tooltip or popover is instantiated on the window.document object itself without a delegated selector: the guard is this.$element[0] instanceof document.constructor && !this.options.selector. Attaching to document only makes sense for event delegation, which needs a selector string to filter which descendants the events apply to.","triggerScenarios":"$(document).tooltip({...}) or $(document).popover({...}) with no selector key in the options object — the element is the document node and options.selector is undefined.","commonSituations":"Migrating init code from per-element $('[data-toggle=tooltip]').tooltip() to document-level delegation and forgetting the selector; copy-pasted snippets from tutorials that init on document; dynamically inserted DOM that developers try to cover by binding to document.","solutions":["Pass a selector for delegation: $(document).tooltip({selector: '[data-toggle=\"tooltip\"]'})","Or initialize on concrete elements instead of document: $('[data-toggle=\"tooltip\"]').tooltip()"],"exampleFix":"// before\n$(document).tooltip(); // throws\n\n// after\n$(document).tooltip({selector: '[data-toggle=\"tooltip\"]'});","handlingStrategy":"validation","validationCode":"var opts = {};\nif (el === document) {\n  opts.selector = '[data-toggle=\"tooltip\"]'; // mandatory for document\n}\n$(el).tooltip(opts);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass selector when initializing on document","Prefer binding to concrete elements or a stable container","Cover delegated-init code with a smoke test that opens one tooltip"],"tags":["javascript","bootstrap","tooltip","configuration"],"backgroundTag":"bootstrap-component-misconfiguration","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}