Search code examples
jquery

jQuery tool tip: Attaching to some anchor tags only


I have an asp.net page where the codebehind will generate some anchor tags on the page dynamically. I want to use jQuery tool tip plugins for those. I want to attach tooltip to those all links (in my document.ready JavaScript).

How can I do it? I have another anchor tags in the page on which I don't want to attach tool tip.


Solution

  • Assign a class to all anchor tags you want to have anchor text, then use a jQuery selector to select only those links and add a tool tip by setting the title attribute of the tag.

    First in HTML

    <a class="tooltip">This link will have a tooltip</a>
    

    Then in jQuery

    $('a.tooltip').attr('title','This is the tooltip that will show');