开发者

jQuery get all divs with specific id

开发者 https://www.devze.com 2023-01-28 21:10 出处:网络
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

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("开发者_JAVA技巧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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号