Vue JS Issue: Button click does not trigger tooltip update

I am currently utilizing Vue 3 alongside Bootstrap 5.2.

In my project, I have successfully implemented a tooltip by the following method:

App.vue

<script>
import { Tooltip } from "bootstrap";
export default {
  mounted() {
    Array.from(document.querySelectorAll(".tooltip")).forEach(
      (tooltipNode) => new Tooltip(tooltipNode)
    );
  }
}
</script>

Now, I am looking to dynamically update the text displayed in the tooltip upon clicking a button:

Component.vue

<template>
  <div>
    <button class="btn btn-success col-12" @click="changeTooltip()">Click to change Tooltip</button>
    <input class="form-control tooltip col-12" data-bs-placement="bottom" :title="tooltipText" />
  </div>
</template>

<script>
export default {
  data() {
    tooltipText: "Test Tooltip Text",
  },  

  methods: {
    changeTooltip() {
      this.tooltipText = "New Tooltip Text";
    }
  }
}
</script>

Unfortunately, the above approach does not result in any changes to the tooltip text on click. How can I make it so that the tooltip text updates correctly when the button is clicked?

No errors are being generated - despite the value of this.tooltipText changing!

Your assistance is greatly appreciated!

Answer №1

Modifying Bootstrap tooltip content involves updating the data-bs-original-title attribute of the element. By changing this attribute, you can effectively change the text displayed in the tooltip.

updateTooltipContent() {
      const newContent = 'Updated Tooltip Text';
      this.tooltipContent = newContent;
      Array.from(document.querySelectorAll('.tooltip')).forEach(
        (tooltipElement) => {
          tooltipElement.setAttribute('data-bs-original-title', newContent);
        }
      );
    },

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

Button cannot be activated upon selecting a row

The goal is to activate a button when a row is selected. However, the button remains disabled even after selecting a row. Below is a snippet of the code as well as a screenshot showing the issue [error_1]: onInit: function () { var oViewMode ...

Can an image map area be identified using radial coordinates?

While I have experience with online Imagemap Generators for rectangular or circular areas in HTML pages, things get a bit tricky when dealing with pie-shaped sections. When trying to make each pie slice a separate area, the image map code generated by thes ...

A guide to selecting the dropdown item labeled as (Select All) using Python and Selenium

edit: Trying to submit parameters for a database-generated report on this page. Successfully modified the start date in the first field using send_keys(), but unable to click on "(Select All)" for fields 3 and onwards, except one. In order to access the h ...

Exploring AngularJS: the power of directives and the art of dependency

According to Angular documentation, the recommended way to add a dependency is by following these steps: Source //inject directives and services. var app = angular.module('fileUpload', ['ngFileUpload']); app.controller('MyCtrl&ap ...

Using JQuery's .mouseover and .mouseout methods to modify font colors on a webpage

Hi there, I'm new to JQuery and trying to experiment with some basic functionalities. I have a simple navigation menu created using an unordered list, and I want to change the font color of the currently hovered list item using JQuery. However, I&apos ...

Sort the images before uploading them

Hey everyone, I'm having an issue with the sortable feature. I am currently using AJAX to temporarily save images and display them without uploading. Now, I would like to be able to sort those images and have a button to save the sorted version. The ...

Incorporate Jquery Append and Each functions into Class addition

I've encountered an issue while trying to retrieve information in JSON format and add an ID to each element. Despite my efforts, my code is not functioning as intended. Although the appending process is successful and I can see all my results in JSON ...

Utilize the ng-controller directive with unique aliases across various sections of HTML code

I'm facing an issue with my ng-controllers when multiple controllers are used on the same page. For instance, I have one controller in the page header, another in a different section of the same page, and one in the content of the page. However, all o ...

"Ensuring function outcomes with Typescript"Note: The concept of

I've created a class that includes two methods for generating and decoding jsonwebtokens. Here is a snippet of what the class looks like. interface IVerified { id: string email?: string data?: any } export default class TokenProvider implements ...

EJS.JS Error: Unable to find the title

I'm facing an issue with a script in express. I have a function that renders a view upon the success of another function. This project involves angular, node, express, and ejs as the view engine. However, when I try to render the view, I encounter an ...

Accessing the chosen value of an ng-model

Currently, I'm attempting to refine some search results by utilizing the chosen value from an ng-select element (stripping away unnecessary formatting and details). Here's what I have so far: <select ng-model="medium" ng-options="medium as me ...

Differences between visibility property manipulation in HTML and JS

One issue I am facing is that when I add a hidden property to a button in the HTML, it remains invisible. <button id="proceed_to_next_question" hidden> Next Question </button> However, if I remove the hidden property and include the following ...

Utilizing a TinyMCE editor within a text area and implementing a posting form through ajax

I am currently using tinyMCE in my textareas and submitting my form through AJAX. However, I am facing an issue where the value in the textarea is not being recorded when I try to save it. This is my text area: <textarea class="form-control" name="cont ...

Ways to resolve the issue of code not relocating the channel within a specific

The script I wrote to create a new category and channel produced an error message: TypeError: Cannot read property 'hasOwnProperty' of undefined. The issue occurs when the channel is not properly placed within the category. Here is the code snipp ...

Replace the image source with a list of images

I am looking to create a dynamic image list using either an array or an HTML list. When I hover over an image, it should change one by one with a fade or slide effect, and revert back to the default images when I hover out. Question 1: What type of list s ...

Enabling communication between App.js and a separate class in React

How can I integrate React Scheduler with JSON data in my app and pass shifts and functions from App.js to DataSheet.js for updating the data? Is there a more efficient way to enable database updates directly from DataSheet? App.js: import React from &apos ...

Using a PHP variable within an AJAX modal window: A step-by-step guide

The main page (main.php) is currently holding a variable called $var = "hello". A modal window (modal.php) is being loaded through AJAX utilizing the following script: var modal_xhr = $.ajax({ 'type' : 'GET', ...

Unable to apply a dotted border to a horizontal rule when a Bootstrap 5 link is present

As I strive to add a dotted border-style to the horizontal rule on my website, an interesting challenge arises when the Bootstrap-5 CDN is included. The border-style does not take effect as expected. Even on Codeply, the border-style works perfectly until ...

expanding the input and duplicating the outcomes

I'm attempting to clone and add values to results in my project. Here's the link to what I have so far: http://jsfiddle.net/QNP3r/175/ Currently, it is functioning adequately with a table element. However, I'd like to make it work with a di ...

What is the best way to free up memory after receiving responseText in a continuous streaming request?

Utilizing xmlHTTPRequest to fetch data from a continuous motion JPEG data stream involves an interesting trick where responseText can populate data even before the request is completed, since it will never actually finish. However, I have encountered some ...