Search code examples
jqueryqtip2

How to get attribute values of the element that jquery.qtip2 selects


My html document looks like this:

<span class="mytooltip" id="P21_12" waarde="56"><img...></span>

I want to pass the values of the id and waarde attributes to a function that retrieves the tooltip text. It works if I hard-code the values :

  $('.mytooltip').qtip({
    content: { text : get_tooltip_text("P21_12","56") }
});

But when I try to to access the attribute values the function is passed empty values.

  $('.mytooltip').qtip({
    content: { text : get_tooltip_text($(this).attr("id"),$(this).attr("waarde")) }
});

I must be doing something wrong here.


Solution

  • I'd guess that this is gone.. you can run an each loop and do it that way:

    $('.mytooltip').each(function() {
        var id = this.id,
            attr = this.getAttribute("waarde"),
            text = get_tooltip_text(id, attr);
    
        $(this).qtip({
            content: { text : text }
        });
    });