{"record":{"id":"1270cc60fb347141","repo":"dotnet/AspNetCore.Docs","slug":"selector-option-must-be-specified-when-initializ-1270cc","errorCode":null,"errorMessage":"`selector` option must be specified when initializing ${this.type} 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":"aspnetcore/mvc/views/tag-helpers/th-components/samples/RazorPagesSample/wwwroot/lib/bootstrap/js/bootstrap.js","lineNumber":1314,"sourceCode":"    delay: 0,\n    html: false,\n    container: false,\n    viewport: {\n      selector: 'body',\n      padding: 0\n    }\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 && $($.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":1296,"sourceCodeEnd":1332,"githubUrl":"https://github.com/dotnet/AspNetCore.Docs/blob/c67a80103a1a74db20784debd919c7fdda96c510/aspnetcore/mvc/views/tag-helpers/th-components/samples/RazorPagesSample/wwwroot/lib/bootstrap/js/bootstrap.js#L1296-L1332","documentation":"Bootstrap 3's Tooltip.init throws when the target element is a `document` instance and no `selector` option is provided. Delegated tooltips on the document need a selector to know which descendants trigger them; a direct document tooltip would fire for every element.","triggerScenarios":"Calling `$(document).tooltip({...})` (or similar on a document node) without a `selector` option. Triggered during component initialization.","commonSituations":"Trying to attach a tooltip to the whole document for global help text; dynamically generated content where the developer bound to document intending delegation but forgot the selector; copy-paste of `$(elem).tooltip()` where elem resolved to document.","solutions":["Add a `selector` option that matches the trigger elements: `$(document).tooltip({ selector: '[data-toggle=\"tooltip\"]' })`.","Bind to a real container element instead of document when possible.","Attach tooltips to the specific elements that should show them rather than delegating from document."],"exampleFix":"// before\n$(document).tooltip({ placement: 'top' });\n\n// after\n$(document).tooltip({ selector: '[data-toggle=\"tooltip\"]', placement: 'top' });","handlingStrategy":"validation","validationCode":"function safeTooltip($elem, opts) {\n  if ($elem[0] instanceof document.constructor && !opts.selector) {\n    throw new Error('Tooltip on document requires a selector option');\n  }\n  $elem.tooltip(opts);\n}","typeGuard":"function isDelegatedTooltipTarget($elem, opts) {\n  return !($elem[0] instanceof document.constructor) || typeof opts.selector === 'string';\n}","tryCatchPattern":"try {\n  $(document).tooltip(options);\n} catch (e) {\n  if (/selector/.test(e.message)) {\n    $(document).tooltip(Object.assign({ selector: '[data-toggle=\"tooltip\"]' }, options));\n  } else throw e;\n}","preventionTips":["Always pass a selector when binding tooltips to document.","Prefer binding to a real container element.","Use data-attribute-driven tooltips (`[data-toggle=\"tooltip\"]`)."],"tags":["bootstrap","tooltip","delegation","configuration"],"backgroundTag":null,"analyzedSha":"c67a80103a1a74db20784debd919c7fdda96c510","analyzedAt":"2026-08-13T17:46:11.763Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}