Reputation: 303
I want to ask what's the differences using with $()
or without $()
. In two cases actually it is working. Is there any differences i really not understand.
jQuery
var harf = $('<p>Hello there</p>').appendTo('body');
$(harf).on('click', function(){
alert('harf');
});
//
var harf = $('<p>Hello there</p>').appendTo('body');
harf.on('click', function(){
alert('harf');
});
Upvotes: 1
Views: 66
Reputation: 382112
The first one is just totally useless. There's no point in embedding a jQuery object in a jQuery object.
Note that you could chain the calls, you don't really need that harf
variable :
$('<p>Hello there</p>').on('click', function(){
alert('harf');
}).appendTo('body');
Upvotes: 5