2

I have a big enterprise web application for which I want to enable jQuery UI tooltip for selected elements. Lot of elements are generated dynamically after the application is initiated and henceeven if I geive id, it does not work. The only way it work is when I do this :

var $dj = jQuery.noConflict();
$dj(function() {
    $dj(document).tooltip({
        position: {
            my: 'left center',
            at: 'right+5 center'
        },
        show: 1300,
        hide: 2999
    });
});

But this enables tooltip for every element on the application which is not desirable. Please guide me !

Thanks

3
  • Why do ID's not work? Commented Aug 12, 2014 at 16:11
  • May be the page is dynamic and loaded after the application is initiated Commented Aug 12, 2014 at 16:18
  • Even if it is dynamic, that still means an ajax call somewhere in your code. You should know when new elements are being pulled in and you should be able to assign appropriate tooltips then. Commented Aug 12, 2014 at 16:31

1 Answer 1

2

Set the items option to add a selector for event delegation.

Example:

var $dj = jQuery.noConflict();
$dj(function() {
    $dj(document).tooltip({
        items: 'a.example',
        position: {
            my: 'left center',
            at: 'right+5 center'
        },
        show: 1300,
        hide: 2999
    });
});

Where a.example selects the element(s) you want to attach the tooltip widget to.

Working demo: http://jsfiddle.net/aockfe7o/

Source: The jQuery-UI API reference

Sign up to request clarification or add additional context in comments.

3 Comments

Pardon my ignorance but here a.example signifies what ? class name ?
I need to enable for tooltip for one element and disable for another one. Can I use items attribute to select the specific elements for which I want to show tootlip ?
Yes. Just select the elements for which you want to enable tooltip for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.