How to Hide the Default Title When Using a Tooltip in JavaScript? Last Updated : 20 Dec, 2024 Comments Improve Suggest changes 2 Likes Like Report The default browser tooltip is shown when a user hovers over an element with a title attribute. To hide this default title, you can use JavaScript to temporarily remove the title attribute while still implementing your custom tooltip.1. Temporarily Remove the Title AttributeThis method removes the title attribute on hover and restores it once the mouse leaves the element. During this time, a custom tooltip is shown near the cursor. HTML <!DOCTYPE html> <html lang="en"> <head> <style> .custom-tooltip { display: none; position: absolute; background-color: #333; color: white; padding: 5px; border-radius: 3px; font-size: 12px; pointer-events: none; z-index: 10; } </style> </head> <body> <div class="tooltip-element" title="This is the default tooltip">Hover over me</div> <div class="custom-tooltip" id="customTooltip"></div> <script> const tooltipElements = document.querySelectorAll('[title]'); const customTooltip = document.getElementById('customTooltip'); tooltipElements.forEach(element => { element.addEventListener('mouseover', function () { const originalTitle = this.getAttribute('title'); this.setAttribute('data-original-title', originalTitle); this.removeAttribute('title'); customTooltip.innerText = originalTitle; customTooltip.style.display = 'block'; element.addEventListener('mousemove', function (e) { customTooltip.style.top = `${e.pageY + 10}px`; customTooltip.style.left = `${e.pageX + 10}px`; }); }); element.addEventListener('mouseout', function () { this.setAttribute('title', this.getAttribute('data-original-title')); customTooltip.style.display = 'none'; }); }); </script> </body> </html> 2. Replace the Title with a Custom TooltipIn this approach, the title attribute is completely removed, and a custom tooltip is displayed using the data-tooltip attribute. This method relies on CSS to show the tooltip. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Custom Tooltip</title> <style> .tooltip-element { display: inline-block; position: relative; cursor: pointer; } .tooltip-element:hover::after { content: attr(data-tooltip); position: absolute; top: 100%; left: 50%; transform: translateX(-50%); background-color: #333; color: white; padding: 5px; border-radius: 3px; font-size: 12px; white-space: nowrap; } </style> </head> <body> <div class="tooltip-element" data-tooltip="This is a custom tooltip">Hover over me</div> </body> </html> Comment A anujpaz9pe Follow 2 Improve A anujpaz9pe Follow 2 Improve Article Tags : JavaScript Web Technologies Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like