When to use '$(this)' and 'this' in a jQuery plugin? (Article on net.tutsplus.com) -
I am now learning jQuery, and Jeffrey was reading an article about him, almost everything is clear, but some point I am still unable to understand.
The problems start with 'Step 3: Creating the plugin', the title 'Title for each', and the next 'Error Checking'.
this.each (function () {$ this = $ (this); var title = this.title; if ($ this.is ('a') & amp; $ this Attr ('title')! = '') {This.title = ''; $ this.hover (function (e) { question
-
This.title - what is this a method? When we use jQuery, we type $ (this) .attr ('title') - and was made to simplify jQuery) code> this.title
is a DOM specification, or is the context of JavaScript embedded methods? I can not understand that this is the keyword When, when do we have to this and when to use $ (this) ? Why do we this.each (func ..., and not $ (this) .each (using func ... (I tested it - and it also works, but what is the difference?) I know that the factory method $ () gives a wrapped set of DOM elements, but why do we use it this.title here (and then $ (this) .attr (' Title ') jobs)? I did a little test. We can type this.title or in the conditional statement $ this.attr ('title') instead of the title , but if we only Use something ( title or $ (this) .atr ('title') instead of this.title in status. This.title = ''; - This does not work.
OK, we have the var title = this.title; is specified. But when we use this variable, why do we declare it?
I think some of you can understand better than me, what I need to understand about, so that I can finish my description ) Thank you very much, if you use JQuery attr (using 'title') it <1}, NewVal) method you are able to apply a single value for all the elements included in your jQuery selector But to change a single element, to manipulate the title attribute of this element New simple
The each () function, this parameter is being repeated that before. When running on a collection of DOM elements, this will be a DOM element if you want to use jQuery functions on DOM elements, you need to wrap them in jQuery again, which means that You need to use $ (this) .doAwesomeness ()
var title possibly $ This.hover ()
Comments
Post a Comment