Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery functions

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #29547
    Makeshift
    Member

    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()

    #79315
    jamygolden
    Member

    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)
  • The forum ‘JavaScript’ is closed to new topics and replies.