Sp Vs S(p)


#1



Me dice que no he definido la variable div


Reemplaza esta línea con tu código.
var $div=  $("div");


#2

$p and p are both identifiers. They have no difference apart from the added $. Both are ordinary variables with nothing special about them. The $ symbol has no meaning, save what we read into it.

$('div')

The above is a jQuery selector that returns a collection of <div></div> element nodes, including their DOM trees (child elements). This is a special object, referred to as a jQuery object. The $ symbol has real meaning. It is the alias of the function, jQuery.

$('div')

is the equivalent of,

jQuery('div')

Programmers may have a convention surrounding the use of $ in variable names. That would be to indicate that the variable references a jQuery object (a collection).

$d = $('div');

Now when we see the variable in the code, we know that it refers to a collection of DIV-nodes.