www.webdeveloper.com
Results 1 to 2 of 2

Thread: custom plugin: how properly return results?

  1. #1
    Join Date
    Dec 2006
    Posts
    145

    Question custom plugin: how properly return results?

    I'm creating my first jQuery plugin to easy get needed data without repeating the same scripts for different elements. I'd like to my plugin could get things like: width, height, position and more of specified element and his parent (I'll need them to use later) in forms like:

    Code:
        $('element').myPlugin(); // will return all
        $('element').myPlugin(width); // will return only width
        $('element').myPlugin(width, height); // will return width and height
    I don't know the way how to get data from plugin in proper form. I tried to figure it out but always get "undefined" or [Object object] as result. I'll be grateful if someone could give me example how my "[[?]]" part should look:

    Code:
       (function($){
        	$.fn.myPlugin = function(options) {
        	
        		var defaults = {
        			width: this.width(),
        			height: this.height(),
        			parentWidth: this.parent().width(),
        			[[more]]
        		}
        		var options = $.extend(defaults, options);
        
            return this.each(function () {
        	
        	var $this = $(this);
        
        	[[?]]
        
        	};
        })(jQuery);

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    this.each always returns the original jQuery element object wrapper on each index.

    use .map( if you want to specify a return value.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles