Jquery live of calls a solution that does not exist

  • 2020-03-30 02:09:06
  • OfStack

In the new version of jquery, the live() method has been removed, so we'll tell you that the function doesn't exist when we call it, and js will report an error.

The solution is to replace it with the on() function,

The original writing was:
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201402/201402261651285.gif? 2014126165151 ">  
If you replace the on() method directly, the newly generated element will not have any effect when it clicks the event again. The new syntax is:
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201402/201402261652276.gif? 2014126165238 ">  
There is a problem here, $("body"), why is it "body"? Actually, we can choose other nodes closer to the #company_logo, which will have better performance. Actually, on() is to find the #company_logo node in the body

Related articles: