JQuery qTip - Trigger before creation

I try to call someFunction() before creating qtip

 $('.selector').qtip({ content: { text: someFunction(this.id) } }); 

This code works, but I think this is a dirty solution. Could there be a start: event like in most jquery plugins (e.g. draggable)? I did not find anything about this in the documentation.

EDIT : Well, this code will not work. It runs the function on pageload, not finding.

UPDATE :

 function someFunction(someId) { // some code ... var searchResult = ' ... some results from the search -> from '+someId+' ... '; return searchResult; } 
+6
source share
3 answers

Use the beforeShow : callback parameter, this is the best way to do this.

Link here.

Remove the brackets from someFunction .

 $('.selector').qtip({ api : { beforeShow : function (someId) { // some code ... var searchResult = ' ... some results from the search -> from '+someId+' ... '; // place text in tooltip } } }); 

Working example.

+1
source

You need to pass someFunction , not someFunction() . The latter calls the function and assigns the return value to text , and then never calls the function again. By passing the function itself, qTip will see this function and call it if necessary.

+3
source

In Qtip2, it changed to jQuery style ui events

 $('.selector').qtip({ events: { render: function(event, api) { }, // old onRender show: function(event, api) {}, // old beforeHide (return false or call event.preventDefault() to stop the show) hide: function(event, api) {} // old beforeHide (same as above) } }) 
0
source

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


All Articles