Note: For Chrome, do not expect $ is always jQuery
.
You can put $
into console to check if it returns default ƒ $(selector, [startNode]) { [Command Line API] }
, if yes means $ is not defined for jQuery
.
Luckily that we have below ways to try:
- Solve the conflict of using
$
, let it be jQuery
without any ambiguity
Firstly, you can put this code snippet
var jq = document.createElement('script');
jq.src = "https://code.jquery.com/jquery-3.3.1.min.js"; /* Include any online jquery library you need */
document.getElementsByTagName('head')[0].appendChild(jq);
into the Console,
then put $.noConflict
into console, if it not returns undefined
, but returns ƒ (t){return e.$===w&&(e.$=Kt),t&&e.jQuery===w&&(e.jQuery=Jt),w}
, it means $
is not defined for JQuery
now.
Next you can continue to input your regional code, then you will find it works well now.
Refer: https://blog.wplauncher.com/run-jquery-in-chrome-console/
- Using
.js
file instead in Chrome, then debug the JavaScript file.
Refer: Chrome DevTools Snippets
- Besides, for some specific version of Chrome, there is a option in UI to set the
page context
(probably removed this function in latest version!)
.