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:
$('p')
will add one or more paragraph elements (wrapped in jQuery magic) to an array .click()
is a jQuery function that will be called on each of the paragraph elements found (in the array) function(){...}
is the definition of that click event, where you can perform any javascript option when the paragraph is clicked this
is a global variable that refers to the calling DOM object, which I believe is window
by default, but in this instance it would be each paragraph HTML element. Because you want to call a jQuery function (hide()
) on the paragraph element, you have to wrap the base (HTML/DOM) object with all the jQuery functions, which is what $(this)
does; it takes this
and adds all the jQuery stuff to it, to turn it into a jQuery object, so that you can call all the jQuery functions. In other words:
this
is the base object$(this)
is almost the same, but its a jQuery object, which inherits the object in scope, so that you can call all the jQuery sugar you want