Tarek Saied
Tarek Saied

Reputation: 6616

Need help understanding code

hi all i am new in jquery

this code in book jQuery in action page 219

why he use .end() method

and thanks :)

(function($){
$.fn.setReadOnly = function(readonly) {
return this.filter('input:text')
.attr('readOnly',readonly)
.css('opacity', readonly ? 0.5 : 1.0)
.end();
};
})(jQuery);

Upvotes: 1

Views: 81

Answers (1)

ThiefMaster
ThiefMaster

Reputation: 318508

A jQuery function should return this to allow chaining.

Using .end() he undoes .filter('input:text') so finally he's returning the this jQuery object.

Upvotes: 3

Related Questions