Hello I\'m a newcomer in JavaScript and JQuery language. I started to see some examples of JQuery script.
i have the following code segment:
It refers to each of p
tags in your selector $("p")
that gets clicked. For example, you can see html of each p
tag you clicked on like this:
$("p").click(function(){
alert($(this).html());
});
Notice also that $(this)
and this
in above context mean different things. The latter this
refers to DOM element itself which won't have jQuery methods/properties available to it, for example:
$("p").click(function(){
alert(this.html());
});
Won't work because html()
won't be available because this
refers to DOM element in there. So if you want to use jQuery methods, use $(this)
instead.