Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selectors don't work in console

I can't for the life of me work this one out. I have js running and 'container state..' is a console log from the running js on the page. It's displaying a selector, but if i want to do anything within the console it just returns null. I'm assuming somehow i'm over writing jQuery function somewhere, as if i called jQuery

>>> $
function()

This is how i am calling a selector

Container state 3 jQuery(div.module-carousel)
>>> $('body')
null  
like image 412
Jamie Hutber Avatar asked Jun 28 '12 10:06

Jamie Hutber


2 Answers

jQuery uses 2 namespaces, jQuery and $. Another library could have used the $. Try using jQuery instead of $ (assuming that it isn't overridden as well):

jQuery('body');

or wrap jQuery in an immediate function and use $ in it so you don't need to replace $ in the existing code:

(function($){
    //"$" in here is jQuery
    //code that uses $ as jQuery will work in here
}(jQuery)); //pass in jQuery and execute
like image 191
Joseph Avatar answered Oct 30 '22 20:10

Joseph


you can use this before writing any command on console.

$ = jQuery.noConflict();
like image 24
Aatif Farooq Avatar answered Oct 30 '22 22:10

Aatif Farooq