Search code examples
javascriptjqueryqtip

How do I make the innerHTML of a block-level element appear in the QTip?


I am using the QTip javascript library on my web page. When the user clicks on a link (which I have made to be block level), a QTip appears.

I have hidden the inner text of the links with text-indent: -10000px;. The text will appear in the QTip that appears after clicking on the link.

I cannot store this text in the title attribute since the title attribute contains other data.

How do I use the QTip API to grab the innerHTML of the element being clicked on? I haven't found it in their documentation yet: http://craigsworks.com/projects/qtip/docs/reference/

I have tried

content: {
    text: $(this).html(),
}

to no avail. Thanks.


Additionally, it might be useful to know that another QTip appears when the user hovers over the link. The content for this other QTip is stored in the link's title attribute.


Solution

  • Try something like this:

    (function($) {
        var $link = $('yourLink'),
            value = $link.html();
    
        $(function() {
            $link.qtip({
                content: {
                    text: value
                }
            });
        });        
    })(jQuery);