Why does the Chrome Dev Console get the error "ReferenceError: $ unspecified failure"?

I am trying to run a simple jQuery script in the Chrome Developer Console, but I have a problem.

There is no problem in this code when I run it in the Chrome Developer Console:

var someValue = $("[name='Jack']");
if(someValue !== null){
   console.log("Jack is here!");
}

But I get an error when trying to run the same code inside a function setTimeout, as shown below:

setTimeout(function(){
   var someValue = $("[name='Jack']");
   if(someValue !== null){
      console.log("Jack is here!");
   }
}, 1000);

Unprepared ReferenceError: $ undefined

Not only does this happen in the setTimeout function, but also in the normal function.

I am working with the latest version of Google Chrome. How can I use jQuery as shown above in a function setTimeout?

0
source share
2 answers

, $ API Chrome. $ , API $. , jQuery: , someValue !== null jQuery. jQuery (someValue.length > 0), null.

, Chrome $ , setTimeout: , , API . setTimeout , Chrome , , API $. , JavaScript. JavaScript, setTimeout , , , . , , - , !


, JavaScript with, . , , , :

var chromeConsoleAPI = { $: function() { ... } }
with(chromeConsoleAPI) {
    // your snippet here
}
delete chromeConsoleAPI.$;

$ chromeConsoleAPI . $, setTimeout chromeConsoleAPI.$, $. , , $. API ( ) .

+3

, Jquery Load custome.

js custome script? script jquery script.

jquery, script.

0

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


All Articles