dangerChihuahua007
dangerChihuahua007

Reputation: 20875

How do I access the triggering element using QTip?

I have a QTip assigned to an element as follows:

$('#myDiv').qtip({
            show: { when: { event: 'click', } },
            hide: { when: { event: 'unfocus' } },
            style: {
                  border: {
                     width: 5,
                     radius: 10
                  },
                  padding: 10, 
                  textAlign: 'center',
                  tip: true, // Give it a speech bubble tip with automatic corner detection
                  name: 'red' // Style it according to the preset 'cream' style
            },
            position: {
                corner: {
                 tooltip: 'topMiddle', // Use the corner...
                 target: 'bottomMiddle' // ...and opposite corner
                }
            },
            content: {
               text: self.parent('.qtip').html(),
               title: { text: 'My Title' }
            },

        });

Under 'text' in 'content', I am trying to access the innerHTML of the element that triggered this QTip to appear after being clicked on.

However, my current means of self.parent('.qtip').html(), as displayed above, is not working.

What is the standard way to do this? Thanks.

Upvotes: 2

Views: 1270

Answers (2)

dangerChihuahua007
dangerChihuahua007

Reputation: 20875

I later found the solution to this question.

To access properties of the element that triggered the QTip, one must structure the code in this way:

$("#container a").each(function() { 
    $(this).qtip({ // QTip code });
});

That way, one can use $(this) to access data such as innerHTML of the element that triggered the QTip.

Upvotes: 7

Ivan Castellanos
Ivan Castellanos

Reputation: 8243

Maybe you could set it before:

var text = $('#myDiv').text();

And use it inside the object:

text: text,

Upvotes: 1

Related Questions