문제

I'm using jquery qtip (http://qtip2.com/)

its working well, i have a number of divs inside with classes

I'm trying to to invoke a click function on these divs

qtip:

 var tipContent = $('#tip-content').html();
    $('#obsglass').qtip({
        content: {
            text: tipContent
        },
        show: {
            effect: function() {
                $(this).fadeTo(500, 1);
            },
            event:'click'
        },
        hide: {
            effect: function() {
                $(this).slideUp();
            },
            event:'click unfocus'

        },
        //show: 'click',
        //hide: 'click unfocus',
        style: {
            classes: 'qtip-bootstrap qtip-shadow',

        },

        position: {
            my: 'center left',  // Position my top left...
            at: 'center right', // at the bottom right of...
            target: $('#obsglass') // my target
        },


    });

Click function

 $(".obsglass-thumbnail").click(function () {

... Not entering this function when clicking the divs in the tool tip

도움이 되었습니까?

해결책

Seem like your elements have been added dynamically to the DOM by the plugin, try to use event delegation here:

$(document.body).on('click','.obsglass-thumbnail',function() {
    // Your code here
})

다른 팁

Instead of ,

 $(".obsglass-thumbnail").click(function () {})

Use delegate :

 $(document).delegate(".obsglass-thumbnail","click",function () {})

Because , IF HTML elements were added after loading Click event , Your event is not useful for those elements.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top