Search code examples
jquerytooltipster

Tooltipster change title using jQuery


Okay I implemented Tooltipster successfully and I have created an image with the following title:

<img id="DeviceIvan" class="tooltipsterIvan" src="Slike/urSamsungS7.png"
title="Some Tekst bla bla works great."/>

Now I have need the title text to change when I select a different option. I usually do this:

$('#DeviceIvan').html("I have changed the text yo!!!");

But this does not appear to work.

I also tried:

var image = document.querySelector('img');
image.title = 'Your title'; // Assigning directly to attribute.
image.setAttribute('title', 'Your other title'); // Assigning by method.

But that also did not work. Can someone help with changing the title using jQuery ?


Solution

  • Your question is quite "minimal"...
    Since I can't see how you implemented Tooltipster, I've done it real simple in this codePen

    Now, once you instantiated Tooltipster, to change the title you have to destroy the first instance, change the title...
    And then, re-instantiate Tooltipster.

    I placed a button in the example to do so.

    // On load instantiation of Tooltipster.
    $('#DeviceIvan').tooltipster({
      theme: 'tooltipster-punk'
    });
    
    $("#test").on("click",function(){
    
      // Destroy the first instance.
      $('#DeviceIvan').tooltipster("destroy");
    
      // change the title attribute and re-instantiate.
      $('#DeviceIvan').attr("title","I have changed the text yo!!!").tooltipster({
        theme: 'tooltipster-punk'
      });
    });