Grow your CSS skills. Land your dream job.

jQuery functions

  • # July 5, 2010 at 4:08 am

    Hey guys, is there a way of doing a function on a jquery object without having to do this:?

    Code:
    $(function(){
    $(‘div’).each(function(){
    $(this).width(‘img’, this).width());
    });
    });

    I just want to be able to use the $(this) without having to do the .each()

    # July 6, 2010 at 1:14 am

    Try this:

    Code:
    jQuery.fn.exampleName= function() {
    return this.width(‘img’, this).width());
    };

    $(document).ready(function(){
    $(“div”).exampleName();
    });

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".