Tips on modifying the color of three distinct tooltip arrows

I managed to give 3 tooltips different colors using JavaScript and data-toggle like this

<span class="tooltipjs" data-toggle="sin-datos" data-placement="right" data-original-title="some text">A</span>
$('[data-toggle="sin-datos"]').hover(function(){
      $('.tooltip-inner').css('background-color', 'blue');
      $('.tooltip-inner').css('color', 'white');
      $('.tooltip-arrow').css('border-right-color', 'blue');
      
  });

It works perfectly in this prototype, where the arrow color matches the background color of the tooltip jsfiddle prototype (I set the "border-right-color" in three different ways for testing purposes).

However, when I implement it in my web app, it doesn't work.

https://i.sstatic.net/2A9t0.png

I can change all the arrow colors with:

.tooltip .arrow::before {
      border-right-color: green;
}

As shown in the picture, but I'm unable to change the color based on different data-toggles like I did with the background-color of the tooltip.

I researched and found that the issue may be related to setting the color inside pseudo elements (::before) which cannot be accessed using JavaScript. Since I have limited experience working with pseudo elements, I am a bit perplexed.

I tried multiple approaches like...

$('.tooltip-arrow').css('border-right-color', 'color');
$('.tooltip > .tooltip-arrow').css('border-right-color', 'color');
$('.tooltip .tooltip-arrow').css('border-right-color', 'color');
$('.bs-tooltip-auto[x-placement^=right] .arrow::before, .bs-tooltip-right .arrow::before').css('border-right-color', 'color');
$('.tooltip .arrow::before').css('border-right-color', 'color');

But none of them seem to work, I am using Bootstrap 4.

Answer №1

It seems like there may be an issue arising from the arrow now being generated with a pseudo element, which does not allow for inline styles to be applied. Here are a few potential solutions:

  • Create a CSS class containing the necessary styles and apply it to the main container (both inner content and arrow). You could also define a data-tooltip-class attribute to create a generic function for applying the correct color on hover.
  • Create your own custom template with a unique arrow rendering technique (possibly using a non-pseudo element).
  • Explore alternative options available in this resource

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

Using Jquery to add links that open in a new tab

I have a client who runs a WooCommerce WordPress site and they want the product image/link on the category page to open in a new tab when clicked. I have been attempting to use jquery to achieve this with no success. As I am relatively new to jquery, any a ...

Displaying nested arrays correctly

My latest endeavour involves constructing a data tree in Vue, utilizing components. Let's examine the provided data snippet: "data": [ { "id": 1, "name": "foo", "children": [ { "id": 2, "name": "bar", "children": [] } ...

Is there a way to adjust the height relative to the viewport in Bootstrap 5 for values other than 100?

Attempting to create a new type of div using a custom stylesheet with minimal non-bootstrap css. I am trying to convert each style rule from my django static files CSS into a bootstrap class, but I am stuck on viewport-based sizing. Prior to discovering t ...

How can I fix the NextJs error that says: "The title element should only have one child element, not an array with multiple elements"?

An issue is arising when attempting to create a component that wraps every page and expects children and a title for each page. The error message states: "Title element received an array with more than 1 element as children." import Head from "next/ ...

The sidebar is misaligned, not following the left alignment set by Bootstrap

While experimenting with Bootstrap, I encountered an issue where an element in the sidebar remains at the bottom instead of aligning to the right as intended. https://i.sstatic.net/LdoS8.jpg I attempted to float it to the right, but its position didn&apo ...

Personalize Radio Buttons and Checkboxes using CSS

Can the styling of radio buttons and checkboxes be customized using only CSS? Many existing solutions involve using images and javascript, but I'm curious if it can be accomplished solely with CSS. ...

Issue Resolved: Received Error Message - Unable to Find Function $(...).datetimepicker in app.js Line 61

Resolved, but still facing an issue with changing the datetime format from MM-DD-YY to DD-MM-YY I've been troubleshooting my datepicker error without success. I've attempted to change it to DD-MM-YY hh:mm format, but it continues to default to M ...

Incorporating database coordinates into Marker React Leaflet: A Step-by-Step Guide

When I retrieve coordinates from the database, they are structured as "lat" and "lon" fields. In my mapping application, I have multiple markers to display. How can I combine these two fields to pass coordinates (coord.lat and coord.lon) to the Marker comp ...

Does the unique identifier of the element remain constant in jQuery?

For example: $("#savenew").live('click', function(e) { var user=<?php echo $user?>; $.ajax({ type: "POST", url: "actions/sub.php", data:{user: user} , ...

Vue3 - Suspense not displaying backup content

I have a parent component and a child component set up as follows: . ├── Index.vue (Parent) └── _GetShipment.vue (Child) Within Index.vue, I am using Office.js's getAsync method to retrieve the content of an email body: <script> imp ...

best way to return a function variable in JavaScript

Hey there, I've been working with react native and have run into a bit of an issue... const SignIn = () => { screensplash() fetch('http://api.megamouj.ir/api/v1/logincheck/', { method: 'POST', headers: { ...

What makes Next.js API so special?

As I delve into Next.js, I find myself grappling with the concept of server-side rendering (SSR) and API usage. When is it appropriate to utilize the API folder within pages versus deploying my own server along with a database? Would there be any conflic ...

Clickable elements are not functioning on dynamically generated divs

In the process of developing an application using Angular, I encountered a scenario where I needed to fetch and display data from a web service. The challenge was in dynamically creating div elements with the retrieved data: for(var i = 0 ; i < data.Ou ...

Numerous Jquery Countdowns embedded within an HTML table

My current project involves displaying the status of multiple auctions on a single page, each with its own end date. I am successfully using cfquery to extract data from the database and then utilizing cfoutput to construct a table. However, my challenge l ...

Is it possible to show or hide a DIV based on the text content of another DIV using JavaScript in

I am looking for a way to dynamically hide a DIV based on user roles using only the text inside a title tag as a reference. Here is an example of the HTML structure: <title>admin</title> If the user role is admin, then hide the following DI ...

Error message: The requested resource in Golang does not have an 'Access-Control-Allow-Origin' header present, which means that the origin 'null' is not permitted to access it

I am currently experimenting with checking if a domain A client can send a domain B cookie to domain B. Here is the Go code I am using: package main import ( "fmt" "net/http" "log" "time" "encoding/json" ) func setCookie(w http.Resp ...

Choose the option from the jQuery dropdown list based on the displayed text instead of the value

In continuation of my previous question on jQuery getting values from multiple selects together, I am working with a select list like this: <select name="access" class="change" id="staff_off" runat="server"> <option value="8192">Off< ...

Having trouble with the setHours function in React not behaving as anticipated?

I'm having trouble adjusting the time in my React application using the setHours method: function App() { let currHour = new Date().setHours(15); return ( <div> <h1>{currHour}</h1> </div> ); } Inst ...

Creating personalized email templates with PHPMailer Using PHP to send customized

I am currently in the process of creating an email feature for a client, with a primary focus on ensuring that users remain on the same page in case of any email-related errors. These errors should be displayed on the same page. To achieve this, I have de ...

Troubleshooting issue: Rails application custom action with Cancancan and Ajax not

After integrating Devise and Cancancan for authentication and authorization in my Rails App, I encountered an issue where a previously functioning action now redirects to the home page when called from the JavaScript form submission. The JavaScript code s ...