Ensure a minimum width is applied to a specific tooltip in Bootstrap that has a dynamically generated ID

I am working on an html view using Thymeleaf. The view contains a large table with various tooltips that have a style applied which is functioning correctly. However, I am now facing the challenge of adding a min-width specifically to the tooltips within a particular column. These tooltips have ids that start with "commentTooltip".

Each tooltip generated by Thymeleaf has an id starting with "commentTooltip".

I have attempted several possible solutions without success so far. I feel like I am close to finding a solution, but struggling to access the .tooltip-inner element which is dynamically generated by Bootstrap after the DOM is ready.

My current approach is:

<td id="commentTooltip6H78SHF data-html="true" data-toggle="tooltip" data-original-title='Tooltip Text One'>
<td id="commentTooltip8RQ671S data-html="true" data-toggle="tooltip" data-original-title='Tooltip Text two'>



$('td')
  .filter(function() {
    return this.id.match(/commentTooltip*/);
  }).next($('.tooltip > .tooltip-inner')).attr('min-width','400px');

This code snippet allows me to select all the td elements that I want to modify, but I am encountering difficulties in accessing the properties of the generated tooltips.

$('td')
.filter(function() {
 return this.id.match(/commentTooltip*/);
 })

Any assistance with this issue would be greatly appreciated. Thank you!

Answer №1

One way to target elements in CSS is by using the syntax [id^=commentTooltip]

The symbol ^= denotes "starts with". On the other hand, $= signifies "ends with". - How to get CSS to select ID that begins with a string (not in Javascript)?

Therefore, you can easily set a minWidth CSS property for all tooltips containing commentTooltip in their ID.

Suppose we have this HTML:

<td id="commentTooltip8RQ671S" href="#">
 <span class="tooltip">tooltip</span> 
    click
</td>

To modify the tooltip styles, you can follow this script:

$('td[id^=commentTooltip]').on('mouseover', function() {
  let tooltip = $(this).children('.tooltip');

  tooltip.css({
   'display': 'inline-block', /* just for display purposes */
   'minWidth': '300px'
  })
})

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

Retrieve the most recent item inside a div using JQuery

Is there a way to use jQuery to target the most recent element within this div that has the class name trackon? (such as #trackline1) Thanks! ...

Using iScroll without animation by using scrolltoelement on an iPhone PhoneGap application

I've been working on an iOS PhoneGap app that uses Backbone and some other libraries. To handle scrolling, I implemented iScroll which has been functioning properly. However, I encountered a problem with the following code snippet: events: { &apo ...

Ways to bypass HostListener in Angular 2

In the process of developing a page with animations triggered on scroll, I encountered the challenge of ensuring that the animations only occur when the corresponding element is visible on the viewport. Utilizing Angular2 for this task led me to investigat ...

The icon for the "Hamburger" menu is missing, but the text is visible

Currently, I am designing the topbar for my website using Foundation. Everything seems to be functioning correctly except for the menu icon not appearing. I have followed the documentation provided by Foundation, but I am still facing difficulties. Here is ...

React: A Guide to Selectively Targeting the State of List Items

Exploring React, I am currently working on creating a dynamic navigation menu by utilizing the map() function to target the ul and li components efficiently while avoiding code duplication. However, I am encountering an issue where clicking to open one com ...

What is the best way to change function.bind(this) to an arrow function in a react native application?

I am attempting to convert my function into an arrow function, but I keep encountering an error of undefined when passing props. <TextInput style={styles.input} value={formState.inputValues.title} onChangeText={textCh ...

The Discord.js guildMemberUpdate event: Everything you need to know

I am currently working on creating a welcome message bot using Discord.js. The goal is to have the bot send a welcome message through a webhook in a specific channel when a member gains access to it. Here's what I have so far: client.on("guildMe ...

Manage unexpected errors by displaying pop-up notifications

Is there a way to display an error message from my backend code in an alert box using javascript? I'm currently working with ASP.NET MVC 1.0. Thank you, Rod. ...

Issues with sending parameters via an initialisation function in JavaScript

I am struggling with passing arguments to a new object when using an initializer function. Let's look at my examples where I aim to create an object that returns an array. Object Ex1 works as expected: Ex1 = function() { myVar = []; myVar = ...

Alignment of slider arrows in a CSS carousel with Bootstrap 4.1.1

Is there a way to position the carousel control arrows at the left and right ends of the screen in Bootstrap 4.1.1? I attempted the code below but it didn't yield the desired result. .carousel-control .icon-prev{ left: 5px } .carousel-control .icon ...

Leveraging javascript to extract data from several input fields and dynamically incorporate them into a table

I'm currently in the process of developing a script that extracts field values and organizes them into a table for verification purposes. The challenge I face is that users have the ability to add multiple fields (up to 5), each with its own unique id ...

Change the global type-selector class dominance

I have a variety of form pages in my application, all with text box elements that share the same global CSS rules like width (150px), font-family, and font-size. To streamline this, I created a global CSS type selector class for most text boxes. However, s ...

What are the best methods for adjusting the size of a game's

I create games using HTML5/CSS/JS, but I am struggling to figure out how to make them scale to different screen resolutions. It seems like a simple task, but I can't seem to grasp it. SOLVED var RATIO = 480 / 800; // Initial ratio. function resize() ...

Incorporating dropdown choices using a JSON format

Currently, I am utilizing ColdFusion 10 for retrieving data via AJAX based on the selected option from a drop-down menu. <script> function loadQuery() { var assign = $("#fcbCountry").val(); $.ajax({ type: 'get', url ...

What could be causing my page to appear at different heights in Safari and Firefox compared to Chrome?

I've been working on www.rootologyhealth.com and I'm stumped by the strange behavior of the Nav Bar on the homepage. It's positioned too high in Safari and Firefox, but appears perfectly in Chrome. Despite my efforts to troubleshoot, I can&a ...

How to make a checkbox list appear bold when checked in AngularJS?

<div class='someClass'> <label ng-repeat="item in itemList"> <input type='checkbox' checklist-model='itemCheckList' checklist-value='item.name'> <span class=& ...

Execute a series of repetitive HTTP GET requests and remain patient for all of them to complete

I am working with a REST service that provides a list of 'Json' objects, where each object may contain a link to another resource of the same class. To fetch all these resources recursively starting from a specific one, I have written the followi ...

Tips for properly nesting a "carousel" div within an "oe_structure" without any overlapping issues

Having trouble with placing a "carousel" div inside the "oe_structure" in my odoo template. I am currently working on editing the "website_sale.products" template. As a newcomer to Odoo, can I use inheritance in my direct code to make edits? I'm stil ...

Exploring anchor hover effects and navigating adjacent sibling elements

Consider this html structure: <p><a></a></p> <div><a><img></a></div> To hide all images inside a div after a p tag, you can use the following code: p + div {display:none;} However, attempting to sho ...

Implementing functions within a loop with the help of requirejs

I'm experiencing a challenge with calling functions within a loop across different modules using requirejs. The function call within the loop is located in module A and triggers a function in module B that initiates an Ajax request using jQuery. Each ...