Utilize a custom attribute in Bootstrap 4 tooltips instead of the standard "title" attribute to define the text displayed in

For my application, I'm utilizing Bootstrap 4 along with tooltips. My objective is to toggle the tooltips individually and only display them upon clicking. The following code allows me to achieve this:

<input type="text" id="name" class="form-control" autocomplete="off" 
data-toggle="tooltip" data-placement="bottom" title="Write name here.">

To show the tooltip one by one, I use the JavaScript snippet below which is triggered upon a button click:

 $('#name').tooltip("show");

To hide or dispose of the tooltip, I use the script provided below:

 $('#name').tooltip("dispose");

The reason behind using "dispose" is that I prefer the tooltip not to be visible unless specifically activated by the button.

An issue arises when hovering over the input field as the browser (in my case Firefox Developer Edition) displays the tooltip with its own styling due to the text being in the title attribute.

I wonder if there's a way in Bootstrap to store the text to be shown in another attribute like data-tooltiptitle, for example:

<input type="text" id="name" class="form-control" autocomplete="off" 
data-toggle="tooltip" data-placement="bottom" data-tooltiptitle="Write name here.">

Perhaps then instructing the tooltip to utilize the data-tooltiptitle attribute for the text via jQuery.

Your guidance on this matter would be greatly appreciated.

Answer №1

If you want to utilize a title option and define it as a function, you can achieve this by triggering the function on hover over the element. By using getAttribute, you can retrieve the specific custom attribute.

$(document).ready(function() {
  $('[data-toggle="tooltip"]').tooltip({
    title: function() {
      return 'No Hooray!!';
    }
  });
  $('#link').tooltip({
    title: function() {
      return this.getAttribute('custom-title');
    }
  });
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

<a href="#" data-toggle="tooltip" custom-title="Hooray!">Hover over me</a>

<input type="text" id="link" custom-title="Hooray!">

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AJAX submission of tinyMCE content - Encoding of special characters within table elements

Currently, I am integrating the tinyMCE editor plugin into my website. When I utilize a basic HTML page post to send the content to the backend PHP for saving it into a database or file, everything works fine. However, when I attempt to achieve the same ...

Rendering illuminated component with continuous asynchronous updates

My task involves displaying a list of items using lit components. Each item in the list consists of a known name and an asynchronously fetched value. Situation Overview: A generic component named simple-list is required to render any pairs of name and va ...

How can one import files from an external CSS template in CakePHP 2.x?

I recently acquired an external HTML template that I purchased from a website called themeforest: https://i.sstatic.net/UIu6g.png The folder structure is as follows: base/ - css/ - fonts/ - images/ - img/ - js/ - index.html The template file Index.html ...

Is there a way to manually add route resolve data to a controller without using automatic injection?

Two routes in my application share a controller, but one route requires data to be resolved before the view loads while the other does not. Here is an example of the routing segments: ... when('/users', { controller: 'UsersCtrl', ...

Examining website design on an IOS device from a Windows computer

Is there a way for me to test HTML files from Windows on iOS8 (Local Files)? I have tried Adobe Edge Inspect, but it only works with servers. Are there any free cloud hosts that allow for HTML, CSS, and JS files? Edit: I apologize if my question was not c ...

Why isn't the onChange function triggering in the input type text when the input is not manually typed in?

I am currently facing an issue with two text fields in my HTML form. Here is how they are set up: HTML : <input type="text" id="input1" onchange="doSomething();" disabled/> <input type="text" id="input2"/> JavaScript : function doSomething( ...

Enhance your Vue.js app with seamless page transitions using the

I am facing an issue and need some help. My goal is to create a web application-like interface. However, when I use vue.js transitions, it displays like this: https://i.sstatic.net/U1g6M.gif The transition automatically resizes, repeats, and changes si ...

Is there a problem with the Drag and Drop API?

So here's the deal: I've encountered a problem with the HTML5 Drag and Drop API. In short, besides the essential dragstart, dragover, and drop events, there are three more events - mousedown, mouseup, and mouseleave - that are crucial for achiev ...

Implement a FOR loop in conjunction with an AJAX request

My goal is to send an AJAX request with multiple form fields and use an array for validations. I would like to also pass these values via AJAX: Although I haven't used a for loop in JavaScript before, it looks familiar. The current approach of the l ...

State of the Browser - JavaScript/jQuery

Looking for a method to identify when my browser is loading and display a loading icon. Is this approach appropriate, or should I follow a more common practice to achieve the same goal? Edit: This feature will be implemented on one of my websites during ...

How does a database contribute to the functionality of a redux application?

Recently, I started exploring redux and finally understood the architecture behind it. In a single page redux application where all data is stored in a central store and updated through frontend actions, what purpose does the back-end and database serve? ...

How to use jQuery to hide the submit button once it's been clicked for processing and update the form's action attribute

I am currently facing an issue and would greatly appreciate any assistance. The situation is as follows: I have a form with a text box and a submit button. The process-page.php file contains a PHP script that queries my database for user information and p ...

Refreshing a form following an ajax call using the ajaxForm method

I have implemented the following code to submit my form using ajaxForm plugin: $('#donations').ajaxForm({ dataType: 'json', beforeSubmit: function(){ $('#message').html(''); ...

Combining Content, Attr, and Url in a single statement

I've been utilizing the content attribute for quite some time now, but today I decided to explore something different. Instead of relying on JS to show an image tooltip, I was curious if it could be done dynamically using CSS. So I attempted the foll ...

When a user hovers over an element, display text in a particular div

I've been experimenting with different methods to achieve this, but nothing seems to be working for me. The idea is that when I hover over a specific div like "divOne" or "divTwo", I want a text to appear in the "writeToMe" div. After spending several ...

How can I implement conditional rendering with React on a div element?

Is it possible to implement conditional rendering by simply adding the boolean checked isVisible=true onto the div? Will this ensure that it only renders when true? Could there be any potential issues with the component's state changing after renderi ...

Internet Explorer 7 does not support the return link feature when using jQuery

My issue involves using jQuery and Ajax, where my Ajax.php file outputs a specific field into the main file. Everything works as expected when I click in Mozilla and Chrome, resulting in an alert pop-up. However, when attempting the same action in Internet ...

Styling X and Y axis font color in charts using JavaFX 2.x CSS

Is there a way to change the font color of both X and Y axes? In my search through the css reference for fonts, I only found properties like font-size, font-style, and font-weight. font-size, font-style and font-weight I attempted to use -fx-font-color ...

In Firefox, using the new Date function within a string does not function as expected

Why does the last log in the code snippet below not work in Firefox? (function() { String.prototype.toDate = function() { return new Date(this); }; console.log(Date.parse("2012-01-31")); console.log(new Date("2012-01-31")); c ...

Navigation panel positioned on one side filling up the entire content container

I am currently developing a fresh website design. I envision a layout with the header positioned at the top, content in the middle, and a footer that will either stay at the bottom of the window if the content is minimal, or go to the bottom of the content ...