Search code examples
javascriptjqueryselectorqtip

qTip dynamic button with jQuery (currently using selectors)


Random elements throughout the page have an attribute named qtip. I would like to find each one, and in the qTip content section, display the contents of the qtip attribute.

$("*[qtip]").qtip({
    content: $(this).attr("qtip"),
    show: 'mouseover',
    hide: 'mouseout'
});

If I don't put the $(this).attr("qtip") and just put static text (e.g. "Test"), it works. However, the $(this) is screwing it up. I there another way to do it? I'm not attached to selectors if there is another way to find all the elements with the qtip attribute.


Solution

  • You can use the .each() function so "this" refers to each element.

    $("*[qtip]").each(function() {
        $(this).qtip({
            content: $(this).attr("qtip"),
            show: 'mouseover',
            hide: 'mouseout'
        });
    });