jQuery: Solution of $(…) is null on pages

Hi Friends, Sometime when you used jquery on somepages and mostly in wordpress then I think you must got encountered with this error “$(…) is null” where … would be your element class name or id. I know this error is very small but really frustating because we didnt find what we are doing wrong. So I also got this issue and solve it and really it seems very easy when I solved this issue.

Anyway when we use $ as jquery object then the $ function in jQuery will never return null. So it is likely it is a different non-jQuery $ in use may be prototype.js or other library being used.We all know that $ is itself not null because the exception would be different, like : “$ is not a function” but In this case the browser is saying that the result of the expression $(…)) is null, which is main cause of this error is $ which is different non-jquery object used by another library.So to solve this error you should use try this :

$(document).ready(function($) {
// your code goes here ...
});

Or you can try this also :

jQuery(function($) {
// your code goes here ...
});

Or you can replace “$” with “jQuery” (without quotes) in your code(which is not a good idea, but works.) Now you can try any of this method and let us know in comment that it is working or not or you can suggest any other solution in comments too.

I am PHP Freelancer, Freelance PHP Developer having more than 5 years of experience, So if you want to do any projects then you can contact me.

Hostgator Hosting in 1 Cent Coupon Code – “1CENTHECOUPON” (Without Quotes).

Subscribe to PHP Freelancer

Enter your email address: