№4 $p vs $('p')


#1

what problem?
i try this
$(document).ready(function() {
var $div = $('div');
});

and this
$(document).ready{(function() {
var $div = $('div')
}());
};


#2

You don't need $(document).ready(function() {});. Try just declaring the variable.


#3

Also, no var if you're using the $ in front of it. The dollar sign is enough. Your code should look like this:

$div = $('div');

#4

thankx man it's work


#5

I don't understand this. Why I don't need to add var before?


#6

@webmaster72760 Take a look at:

If you declare a variable without the var in front, it's a global variable. So, you could do this:

var foo = function() {
  bar = "baz";
}

foo();
bar;

...and it'd work. But this:

var foo = function() {
  var bar = "baz";
}

foo();
bar;

...wouldn't, because with var, bar is just a regular variable, not global, so it can't be accessed outside of the function unless the function returns it.


#7

$div = $('div');
do this it works :slightly_smiling:


#8

Your code should be like this:

$(document).ready(function() {

});

    var $div = $('div');