javascript dollar sign variable not working
May be you're trying to use jQuery when dom in not build. Try to use $(document).ready
function:
(function ($) { $(document).ready(function () { $header = $("div.header"); $header.remove(); });})(jQuery);
About what you have mantioned in the question:
jQuery(document).ready(function ($) { // code});
It works because it do the same thing: it binds event handler on ready
event and pass jQuery
object as a parameter to the function as $
.
Now what you did before:
(function ($) { $header = $("div.header"); $header.remove();})(jQuery);
Here you just declare anonymous function with named $
parameter:
function ($) {}
And call it with jQuery
object as a parameter, which will be available in the function as $
:
(function ($) {})(jQuery);