Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 710327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:36:31+00:00 2026-05-14T04:36:31+00:00

I have been trying to make this to be a little jQuery plugin that

  • 0

I have been trying to make this to be a little jQuery plugin that I can reuse in the future without having to write the following into my actions.js file in full.

This works when loaded in the same file where I set the height using my variable tallest.

var tallest = null;
$('.slideshow img').each(function(index) {
  if ($(this).height() >= tallest ) {
    tallest = $(this).height();
  }
});
$('.slideshow').height(tallest);

This works and will cycle through all the items, then set the value of tallest to the greatest height found. The following however does not work:

This would be the plugin, loaded from its own file (before the actions.js file that contains the parts using this):

(function($){
  $.fn.extend({
    tallest: function() {
      var tallest = null;

      return this.each(function() {
        if ($(this).height() >= tallest ) {
          tallest = $(this).height();
        }
      });
    }
  });
})(jQuery);

Once loaded I am trying to use it as follows:

$('.slideshow img').tallest();
$('.slideshow').height(tallest);

However the above two lines return an error of ‘tallest is undefined’. How can I make this work? Any ideas would be appreciated. Thinking about this even more the perfect usage of this would be as follows:

$('.container').height(tallest('.container item'));

But I wouldn’t even know where to begin to get this to work in the manner that you pass the object to be measured into the function by adding it into the brackets of the function name.

Thanks for reading,

Jannis

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:36:31+00:00Added an answer on May 14, 2026 at 4:36 am

    The reason you’re getting ‘tallest is undefined’ is because tallest only exists inside the scope in which it is defined and can’t be accessed from outside. You need to encapsulate all your logic inside the plugin. Here is how you might do it:

    (function($) {
      $.fn.tallest = function(itemsSelector) {
        return this.each(function() {
          var $this = $(this),
            $items = $(itemsSelector, this),
            tallest = 0;
    
          $items.each(function() {
            var $thisItem = $(this);
            if ($thisItem.height() > tallest) {
              tallest = $thisItem.height();
            }
          });
    
          $this.height(tallest);
        });
      };
    })(jQuery);
    
    // used like this:
    $('.container').tallest('.item');
    

    Edit:

    Starting a variable name with a $ is a convention inspired by Hungarian Notation and is used to indicate that the variable contains a jQuery object. It’s not required to name your variables this way, but I find it useful.

    I also use var $this = $(this); here to store a jQuery object that wraps the DOM object currently being operated on. The reason for doing this is for performance – every time you need to reference the current object in the loop, you can use $this and won’t be creating an identical new object in memory. In this example the benefit is not very clear because $this is only used once anyway. This technique is also used inside the inner loop by assigning the current object to $thisItem. Since this object is referred to twice in the loop, you save an object instantiation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to create a menu panel with jQuery that can be
I have been trying to make radio buttons without the dot which toggles. I
I have been trying to create rotating object using jQuery and without any other
I have been trying to make my website performs well. One way that may
I have been trying to make a case for using Python at my work.
I have been trying to get around this error for a day now and
I am working on a little WinForm app and have been trying to find
I've been trying to make a little simple game just to test my logics,
I have been trying to teach myself MEF, starting with this tutorial: http://blogs.msdn.com/b/brada/archive/2008/09/29/simple-introduction-to-composite-applications-with-the-managed-extensions-framework.aspx There
So I have been trying for hours to get this to work and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.