JQuery.fn.extend() method actually extends the jQuery prototype ($.fn) object to provide new methods which can be chained to JQuery. For e.g- After searching the elemnts using Jquery, I want to call my custom methods that too with chaining, in that case I will extend it.
- <label>
- <input type="checkbox" name="foo" />
- Foo</label>
- <label>
- <input type="checkbox" name="bar" />
- Bar</label>
- <script type="text/javascript">
- jQuery.fn.extend({
- check: function () {
- return this.each(function () {
- this.checked = true;
- alert('f');
- });
- },
- uncheck: function () {
- return this.each(function () {
- this.checked = false;
- });
- }
- });
-
- $("input[type='checkbox']").check();
-
- </script>
Hope this helps you.