bomortensen
bomortensen

Reputation: 3396

jQuery get all divs with specific id

i Stackoverflow,

I'm trying to get my head around make tooltips to show a description for each item in my asp:Repeater control. The problem is my jquery have to loop through all the divs and make a .tooltip(). I have tried to use the each() function in jQuery, but there's no tooltip showing up :-/

My current code:

<script type="text/javascript">
$(document).ready(function () {
    $('.tooltip').each(function (index, domEle) {
        domEle.tooltip();
    });
});
</script>

And my repeater:

<asp:Repeater ID="rptListPartners" runat="server">
<HeaderTemplate>
<table border="0" cellpadding="7" cellspacing="0">
</HeaderTemplate>
<ItemTemplate>  
    <tr>
        <td style="font-family:Verdana; font-size:11px; height: 18px; width:400px;">
            <div id="data_tooltip_from_div" style="display:none;"> <%#Eval("profile") %></div>
                 <a id="tooltip_from_div" href="#" class="tooltip"> <%#Eval("name") %>, <%#Eval("address") %>, <%#Eval("zip") %> <%#Eval("city") %> <a href='<%#Eval("homepage") %>' target="_blank"><img src='/kort/www.png' /></a></a>
            </td>
            <td style="font-family:Verdana; font-size:11px; height: 18px;"><%#Eval("phone") %></td>               
    </tr>
</ItemTemplate>
<FooterTemplate>
    </table>
</FooterTemplate> 
</asp:Repeater>

Is this approach totally off, or? :-)

Any hint will be greatly appreciated!

Thanks in advance!

Upvotes: 0

Views: 1256

Answers (1)

Nick Craver
Nick Craver

Reputation: 630389

Inside your .each() domEle refers to the DOM element directly, not a jQuery object that has the .tooltip() plugin method...so it should look like this:

$(document).ready(function () {
    $('.tooltip').each(function (index, domEle) {
        $(domEle).tooltip();
    });
});

But...it's a plugin, so there's no need to loop at all:

$(document).ready(function () {
    $('.tooltip').tooltip();
});

IDs have to be unique...it's not causing the error here but remove it if it's repeated to be valid and avoid other issues later. You already have the class you need to select the elements you're after here.


Also, you should be seeing a JavaScript error in your console with your current approach, this will tell you exactly what's going on. If you're in a browser without a console I'd recommend grabbing Firefox and FireBug to go with it, or Chrome and it's included developer tools.

Upvotes: 2

Related Questions