JQuery qTip callback not working

I have a qTip that is called on table elements.

$('#orders_table a[rel]').each(function (){
            $(this).click(function(){
                return false;
            }); 
            $(this).qtip({
                content: {
                    // Set the text to an image HTML string with the correct src URL to the loading image you want to use
                    text: 'Loading...',
                    url: $(this).attr('rel'),
                    // Use the rel attribute of each element for the url to load
                    title: {
                        text: 'Order Number ' + $(this).text(),
                        // Give the tooltip a title using each elements text
                        button: 'Close' // Show a close link in the title
                    }
                },
                position: {
                    corner: {
                        target: 'bottomMiddle',
                        // Position the tooltip above the link
                        tooltip: 'topMiddle'
                    },
                    adjust: {
                        screen: true // Keep the tooltip on-screen at all times
                    }
                },
                show: {
                    when: 'click',
                    solo: true // Only show one tooltip at a time
                },
                hide: 'unfocus',
                style: {
                    tip: true,
                    // Apply a speech bubble tip to the tooltip at the designated tooltip corner
                    border: {
                        width: 0,
                        radius: 4
                    },
                    name: 'light',
                    // Use the default light style
                    width: 570 // Set the tooltip width
                }
            })
        });

Then I have the following callback function:

$('#orders_table a[rel]').each(function (){

            $(this).qtip({
            api: {
                onContentLoad:function() {
                        $('#select').change(function(){

                                alert('test');
                        });    
                }
            }                         
            })
        });

qTip loads dynamic content. This dynamic content has a select box with the identifier "select".

For some reason, it apparently does not call the function AFTER qTip has loaded the dynamic content.

Any ideas? I tried onRender and onContentUpdate which don't seem to fit.

Thank!

+3
source share
3 answers

ID . ID .

.

+1

100%, , , qTip ajax ajax- , qTip un- DOM, .

, qTip . , .

0

, . , , , qTip, ID ( #select , ).

You can do this by changing your choice to the presence of a class (or not, if it is the only one <select>in the content), for example:

<select class="mySelect">

Then, when linking, find this element in the callback, for example:

$('#orders_table a[rel]').each(function (){
  $(this).qtip({
    api: {
      onContentLoad:function() {
        this.elements.content.find('select.mySelect').change(function() {
          alert('test');
        });    
      }
    }                         
  });
});

Also, if you do not need a loop .each()for another reason, you can shorten it to:

$('#orders_table a[rel]').qtip({
  api: {
    onContentLoad:function() {
      this.elements.content.find('select.mySelect').change(function() {
        alert('test');
      });    
    }
  }
});
0
source

Source: https://habr.com/ru/post/1769277/


All Articles