Results 1 to 2 of 2

Thread: custom plugin: how properly return results?

Hybrid View

  1. #1
    Join Date
    Dec 2006

    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:

        $('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:

        	$.fn.myPlugin = function(options) {
        		var defaults = {
        			width: this.width(),
        			height: this.height(),
        			parentWidth: this.parent().width(),
        		var options = $.extend(defaults, options);
            return this.each(function () {
        	var $this = $(this);

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

    use .map( if you want to specify a return value.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

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