Move document.ready function to separate javascript function?

Is it possible to move the following code inside jQuery document.ready into a separate javascript function so that it can be called just like any other javascript function, i.e.

<script type="text/javascript"> 
$(document).ready(function()
{
   $('div#infoi img[title]').qtip({
      position: { 
         adjust: { x:-110, y:0 },
         corner: {
            target: 'bottomLeft',
            tooltip: 'topMiddle'
         }
      },
      style: {
        width: 250,
        padding: 5,
        background: '#E7F1FA',
        color: 'black',
        textAlign: 'center',
        border: {
          width: 3,
          color: '#65a9d7'
        },
        tip: 'topRight'
      }
   });
});
</script>

If so, how, if not, then this answers my question.

+3
source share
2 answers

Pekka's answer is correct, but you may need other information, for example. what it's called, for example, if we have this:

$(document).ready(function() {
  alert("DOM Ready!");
});

Then put it in a named function, for example:

function myFunc() {
  alert("DOM Ready!"); 
}

Now you can call it using myFunc()anywhere ... if you still want to call it on document.ready, the syntax is very short, for example:

$(myFunc);
//this is equivalent to:
$(document).ready(myFunc);

, function() { }, , , .ready(myFunc) $("#thing").click(myFunc), :)

+5

, , - , , ! , , , , , ?

,

$(document).ready(function()

function my_function_name()
0

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


All Articles