The Bootstrap Tooltip seems to be glued in place

Utilizing jQuery, I am dynamically generating a div that includes add and close buttons. Bootstrap tooltips are applied to these buttons for additional functionality. However, a problem arises where the tooltip for the first add button remains visible even when hovering over another add button. See the screenshot for reference. Any suggestions on how to resolve this issue? https://i.stack.imgur.com/J38kd.png

The dynamic divs are created using the jquery clone method.

$(document).on('click', ".addFilesBtn", function(e) {
 e.preventDefault();
 $(".appendClass:first").clone().appendTo".addFiles");
 $('.closeFilesBtn').show();
 $('.closeFilesBtn:first').hide();
});

I've attempted to hide the tooltips using the following code snippet, however, the tooltip for the first button persistently stays visible.

$(document).on('mouseleave','[data-toggle="tooltip"]', function(){
      $(this).tooltip('hide');
});

Updated HTML Code:

<div class="row addFiles">
    <div class="appendClass" style="margin-bottom: 1.5%;">
        <label style="white-space: nowrap;" class="responsive-enter-details col-sm-3 control-label">Select Files</label>
        <div class="col-sm-8 col-md-9">
            <div class="fileinput fileinput-new" data-provides="fileinput">
                <div class="form-control" data-trigger="fileinput">
                    <i class="glyphicon glyphicon-file fileinput-exists"></i> <span class="fileinput-filename">Click to select file</span> <i class="fa fa-upload pull-right"></i>
                </div>
                <input id="inputfile" type="file" style="display: none;">
            </div>
        </div>
        <button class="btn btn-box-tool addFilesBtn" data-toggle="tooltip" title="Click to add more files">
            <i class="fa fa-plus"></i>
        </button>
        <button class="btn btn-box-tool closeFilesBtn" data-toggle="tooltip" title="Click to remove this block">
            <i class="fa fa-times"></i>
        </button>
    </div>
</div>

Link to JS Fiddle: https://jsfiddle.net/gLkrsbxc/4/

Upon inspection in the provided JS Fiddle link, it is evident that the tooltips remain persistent and are not hidden as intended.

Answer №1

Please refer to the latest update for the solution

As stated in the documentation on http://getbootstrap.com/javascript/#tooltips, it is necessary to initialize all tooltips like this:

$(function () {
  $('[data-toggle="tooltip"]').tooltip()
})

Hence, after adding tooltips to the DOM, make sure to initialize them by adding

$('[data-toggle="tooltip"]').tooltip()
within your click function after cloning.

$(document).on('click', ".addFilesBtn", function(e) {
  e.preventDefault();
  $(".appendClass:first").clone().appendTo(".addFiles");

  //initialize tooltips(add this line)
  $('[data-toggle="tooltip"]').tooltip();

  $('.closeFilesBtn').show();
  $('.closeFilesBtn:first').hide();
});

If initialized correctly, you may not need the hide function.

Update:

I believe that directly calling the initializing function might not work flawlessly when there are DOM manipulation operations taking place. To overcome this, introduce a slight delay with setTimeout after appending and before initialization as shown below:

$(document).on('click', ".addFilesBtn", function(e) {
  e.preventDefault();
  $(".appendClass:first").clone().appendTo(".addFiles");

  //initialize tooltips(give some time for dom changes)
  setTimeout(function() {
    $('[data-toggle="tooltip"]').tooltip();
  }, 50);

  $('.closeFilesBtn').show();
  $('.closeFilesBtn:first').hide();
});

Update 2

Prior to cloning, ensure to hide the tooltip of the button being clicked:

$(document).on('click', ".addFilesBtn", function(e) {
    e.preventDefault();

    //hide the tooltip
    $(this).tooltip('hide');

    $(".appendClass:first").clone().appendTo(".addFiles");
    $('.closeFilesBtn').show();
    $('.closeFilesBtn:first').hide();
});

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

Encountering a red squiggly line while working on an Angular 2 project in an HTML file within Visual Studio

Whenever I incorporate Angular 2 code into my HTML files, I notice red squiggly lines appearing like this: Hovering over the red squiggly lines does not reveal any errors or warnings. It may be worth mentioning that I am currently utilizing ReSharper Ult ...

How do I connect to a different application's view?

When working with a view that has tiles, I am looking to click on one of them and be directed to a different application that I have created. In typical cases, I would specify the view folder for navigation. However, when attempting something similar for ...

The information retrieved from the API is not appearing as expected within the Angular 9 ABP framework

I am facing an issue with populating data in my select control, which is located in the header child component. The data comes from an API, but for some reason, it is not displaying correctly. https://i.stack.imgur.com/6JMzn.png. ngOnInit() { thi ...

Using Vue.js to Delete an Element from an Array

I am facing an issue with my form value where the IDs are not getting deleted when I remove data. Each time I save data, a new ID is added to the list in the form value. But when I delete any of those data entries, the corresponding ID is not removed from ...

Steps to reveal a child element when the parent is set to overflow:hidden

There seems to be an issue with a child element having overflow:visible; while the parent element has overflow:hidden;. The height of the child element exceeds that of the parent element. Why is the child element hidden even when its overflow property is ...

What strategies work best for managing jQuery ajax calls that run asynchronously?

Currently, I am working on a project that heavily relies on client-side jQuery and JavaScript. However, I have encountered difficulties in getting one of the screens to function properly. One particular function in my code looks like this: function init{ ...

Retrieve the values from multiple columns within a jqgrid row

Is it possible to retrieve both the first column value and the second column value from a jqgrid row? In my other program, I am currently using this code to obtain the first value of the row: $("#tblTallySheet").jqGrid('getGridParam', 'selr ...

Adding elements to an array within a JSON object in Angular: What you need to know

Within my json object named "flowComponents," there is a string called "name" and an array of strings labeled "edition." As an example: { "_id": "553e87f3205465e83b46999b", "name": "FLOWCOMPONENT_CONTACTCOMBINATION_EDITION", "__v": 0, "edition ...

Can you identify the language of this HTML include code snippet?

Recently, I came across some .html files that include tags in a different format: [% INCLUDE '/path/to/footer.html' %] This bracket-and-percent-sign tag is unfamiliar to me. Does anyone know what it is used for? ...

Exploring the application of Nested Maps in extracting parameters for the getStaticPaths

Your data structure is organized like this: data = { "cse": { "first": [ "Computer Hardware Essentials", "Computer System Essentials", "Cultural Education" ], "second&qu ...

Having trouble getting Django to display images using jQuery? Uncaught Reference Error may be preventing it

Currently, I am experimenting with implementing a jquery example on my django-based website. As I am still in the learning phase, I kindly ask for your patience. This is a snippet of what my code looks like at this point: {% extends "base.html" %} {% loa ...

Where can content-tag and main-tag be found in vue-virtual-scroller?

I've been trying to wrap my head around the vue virtual scroller. I couldn't help but notice in the demo that it utilizes a few HTML attributes... <virtual-scroller v-if="scopedSlots" class="scroller" :item-height="itemHeight" :items="items" ...

"Troubleshooting: Jquery Draggable Function Fails to Execute

I'm currently working on a JSP page where I am attempting to make the rows of a table draggable. Despite multiple attempts and combinations, I have been unable to make any elements draggable. The rows are appended after an AJAX call, but still no succ ...

The Material UI React radio buttons have the ability to modify the value of previous buttons

I'm facing an issue with my Material UI React Stepper Component that contains a group of radio buttons. The problem is that changing the radio button in one step affects the selected value in previous and future steps. I've experimented with diff ...

Return an array that has been filtered to exclude any elements that are also found in a separate array

I have an API that provides a list of cars. const getAsset = async () => dbApi('list_cars', ['', 100]) .then(result => result.map(e => e.symbol)); Here, the function getAsset returns the car list. 0: "BMW" 1: "HONDA" 2: " ...

Having trouble retrieving the data associated with a specific ID from my datatable

I am looking to specifically load the UserData that belongs to the correct AdminId In this code snippet, all the UserData is loaded successfully. It's working fine. async mounted() { this.userData = (await DataService.index()).data; } Now, I wa ...

ReactJS - Element not specified

I'm experiencing a specific issue with the component below related to the changeColor() function, which is triggering an error message: TypeError: Cannot set property 'color' of undefined This error seems to be isolated within this compo ...

Traverse an HTML table and modify its content using an AJAX GET request

After constructing a small ASP.NET Core MVC application, I encountered an issue with loading and displaying images from blob storage on the webpage. The challenge lies in the heaviness of the call, causing the images to load slowly after the webpage itself ...

Initiate a webpage reload

Currently, I am developing an android application specifically designed for tablet devices. This application will display a simple HTML page with text that will be shown for extended periods of time, sometimes up to several hours. The content on this page ...

Transferring a JavaScript variable to PHP after it was added using AJAX techniques

First and foremost, I want to express my gratitude to everyone who has provided assistance on this platform. Your support has been invaluable and has helped me navigate through the challenges of completing my thesis. Currently, I am working on an experime ...