Can a single qtip be used in multiple locations, each with different content?

Greetings,

I recently implemented qTip on my website and here is a snippet of how the document ready function appears:

    $.fn.qtip.styles.mystyle = { // The last part indicates the style name
       width: 200,
       background: '#ebf1ff',
       color: 'black',
       textAlign: 'center',
       border: {
          width: 1,
          radius: 4,
          color: '#AACCEE'
       },
       tip: 'bottomLeft',
       name: 'dark'
    }



   $('.controlTitleContainer .icon').qtip({
       content: $(this).find('.tooltip').html(),
        position: {
              corner: {
                 target: 'topRight',
                 tooltip: 'bottomLeft'
              }
           },
       style: 'mystyle'
    });

The initial part deals with styling, while the latter determines the qtip content.

A typical section of my HTML code looks like this:

 <div class="controlTitleContainer">
      <div class="text">
           <label for="ModelViewAd_Title">Title</label>
      </div>
      <div class="icon">
           &nbsp;<div class="toolTip">MyToolTipTest</div>
      </div>
  </div>

Note: The toolTip class is set to Display : none, and the icon class div will display the tooltip

I will have multiple HTML sections like this on a single page with different data. I would like the tooltip to display the current inner html of each section. Is there a way to achieve this without generating a declaration of qtip for every HTML snippet?

Your advice is greatly appreciated.

Best Regards

Answer №1

Why not consider implementing it in this way?

$(document).ready(function(){
    $.each($(".tooltip"), function(i,val){
        $.fn.qtip.styles.mystyle = { 
           width: 50,
           background: '#ebf1ff',
           color: 'black',
           textAlign: 'center',
           border: {
              width: 1,
              radius: 4,
              color: '#AACCEE'
           },
           tip: 'bottomLeft',
           name: 'dark'
        }

        var theContent = $(val).html();
        $(val).qtip({
            content: theContent,
             position: {
                      corner: {
                         target: 'topRight',
                         tooltip: 'bottomLeft'
                      }
                   },
               style: 'mystyle'
        });
    });
});

By utilizing this method, any div with class="tooltip" will automatically activate qTip. This is the approach I took for my own project.

Below is an example of how I tested it in HTML:-

 <div class="controlTitleContainer">
      <div class="text">
           <label for="ModelViewAd_Title">Title</label>
      </div>
      <div class="icon">
           &nbsp;<span class="tooltip">MyToolTipTest</span>
           &nbsp;<span class="tooltip">MyToolTipTest2</span>
           &nbsp;<span class="tooltip">MyToolTipTest3</span>
      </div>
  </div>

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

Developing a dynamic web application using ASP.NET MVC 5 and implementing an ajax.beginform() feature

Hey there, I'm currently working on a web application project and I've run into a bit of a snag while trying to implement search using ajax. I've created a search form using ajax.beginform(), but here's the problem: when the textbox fi ...

The jQuery autocomplete feature seems to be malfunctioning as no suggestions are showing up when

I am currently generating input text using $.each: $.each(results, function (key, value) { if (typeof value.baseOrSchedStartList[i] != 'undefined') { html += "<td><input type='te ...

What is the best method to show a scrollbar in IE8 while in fullscreen mode?

Is there a way to make the vertical scroll bar appear when using full screen mode in my browser? When I press f11, the scroll bar disappears on the right side and I can't scroll down the page. My body is overflow: visible. ...

When the browser is resized, the fadeIn() function restarts from the

My plan was to create a dynamic effect where a browser-sized div would rotate through 3 different backgrounds using jQuery's fading effect. However, I encountered an issue - whenever I resize the browser window, the effect restarts from the beginning ...

Using .css() will not change the background color

Everything seems to be working fine with the code, but for some reason, when I tried copying it over to my friend's website, the color isn't updating as it should. It's strange that it's not working now. [https://pastebin.com/jm8s6gzX] ...

Is there a way to fully load an entire HTML page on success using AJAX?

$.ajax({ type:'GET', url:"/" , data:{"user": user}, //user is a variable success:function(data) { I would like to display the entire HTML content received from my views here. } }); ...

Retrieve a property from a designated element within the DOM

Is there a way to specifically extract the src attribute of the second image in an HTML file using PHP DOM parser? foreach($html->find('img[src]') as $element) $src = $element->getAttribute('src'); echo $src; I s ...

What is the best way to insert content into HTML elements based on the style sheet used?

Having two style-sheets that can be loaded by user choice presents an interesting challenge. The available style-sheets are named one.css and two.css. My goal is to dynamically change the content when the user switches themes. Here is what I have attempted ...

Adjusting the height of a Jquery Fancybox to allow for scrolling down

I've implemented fancybox to display certain pages on my website, but I'm struggling with setting a fixed height and enabling scrolling for content that exceeds this height within the fancybox. Here are the parameters I have used: <script> ...

Tips for utilizing the !isNan method within a Jquery function to calculate the sum of values in both columns and rows within an HTML table

I am facing an issue with sum calculation in a table where some columns contain text strings and others contain numbers. When I perform the sum calculation, many NaN results are displayed. How can I remove these NaN values? I want to exclude Text string ...

What is the best way to completely fill a column with a horizontal HTML list?

When I split a row into two parts using a div, I encounter an issue where a horizontal html list only displays within the area that the div occupies (Col-6). How can I make this html list expand to fill the entire column? <div class="col-6"> ...

What's the best way to conceal scrollbars in Nuxt2 whilst preserving one for the description?

The Issue My goal is to remove scrollbars from all pages (which I achieved successfully), but keep one visible for a specific section of description. What I Attempted I tried adding the class .scroller and only displaying it for the <div> containi ...

I am having issues with my dropdown-list on my second script not functioning properly

Hello there! I'm new to this platform and English is not my strong suit, so bear with me. I've encountered an issue in my code that I need help with. Step 1: I successfully created the first dropdown list. Step 2: The second dropdown l ...

Organize pictures and words side by side on both sides at the same time

I am currently facing an issue while trying to load images and quotes vertically on the left and right side of the page. The problem arises with the 3rd image and quote due to an unexpected margin in the CSS code. Despite my efforts, I have not been able t ...

Utilize AJAX to enhance the functionality of the form

I am running into an issue with my ajax form submission. Take a look at the code snippet below: <form id="form" method="get"> <input type="text" name="name" id="name"><br> <input type="text" name="email" name="email"><b ...

Attempting to transfer a char pointer to the "QUERY_STRING" to a char array variable, but receiving an incorrect outcome

I'm currently working with FastCgi to create a dynamic HTML webpage. While I can easily retrieve the QUERY_STRING, I am facing difficulties in copying it into a char array. If there's a more efficient way to extract the value from QUERY_STRING, ...

Changing the position to fixed causes the image to resize as you scroll

I am trying to achieve a fixed image effect when it appears on the screen during scrolling, but I want it to return to its normal position if the user scrolls back up. The issue I'm facing is that when I use a JavaScript function to change the image p ...

Is it problematic to redirect before an Ajax call is complete?

I'm facing an issue with my ajax call that involves a redirect happening after the call returns within the success handler: $.ajax({ type: "POST", url: "/LoadSomeData", dataType: "json", success: function (response) { ...

Struggling to create a SVG Line with DOM Manipulation in Typescript

I'm having trouble adding an SVG element to my div using the appendChild function in TypeScript. I want to add a line inside the SVG, but for some reason, I can't see the line output on my browser. There are no errors showing up either. Please he ...

Tips for arranging two columns and two rows on mobile using Bootstrap 5

I'm currently using bootstrap 5, and I need to display 2 columns and 2 rows on my mobile device, but it's only showing 1 row. I have two PSDs for this layout in desktop mode: https://i.sstatic.net/HWG6e.png And for mobile mode: https://i.ssta ...