javascript - What are the pros and cons of calling jQuery functionality via these 2 different methods? -


I'm trying to understand the difference between these 2 methods of javascript / jQuery functions (if any) I am / P>

Method 1, in document.ready () :

  $ ('body'). ('Click', 'a.popup', pop up);   

then

  function popup () {$ (this) // do something}   

Method 2, In document.ready () :

  popup (); Then click  
  function popup () {$ ("a.popup") (function (e) {// do something here}) ; }   

All advice appreciated.

The popup function in method 2 is called only once, otherwise you are equal Functions onclick often attach, what you probably do not want is the popup function body directly in document.ready () . .

There is no big advantage in writing, the advantage of method 1 is that if you want to attach the same function to different events and / or with different elements such as onclick , onmousemove etc. In this way you will not have to type the body of the function twice.

In short, I do not get the benefit in method 2, while I look at method 1.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -