How can I make the divs resize automatically and have them equal in height when the window is resized?

I need to adjust the height of three column divs so that they are all equal. Initially, I was able to achieve this using a function found on SO (apologies for not being able to provide attribution at this time, will update if possible):

function resizeIt()
{   
var largest = 0;

$(".feature").each(function(){ 
   var findHeight = $(this).height(); 

   if(findHeight > largest){ 
      largest = findHeight; 
   }
});

$(".feature").css({"height":largest+"px"});
}

This worked well, but now I want the divs to resize whenever the window is resized. So I made modifications to the function and called it both on page load and window resize. Here is the updated function along with the call for window resize:

function resizeIt()
{
$(".feature").css({"height: auto"});

var largest = 0;

$(".feature").each(function(){ 
   var findHeight = $(this).height(); 

   if(findHeight > largest){ 
      largest = findHeight; 
   }
});

$(".feature").css({"height":largest+"px"});
}
resizeIt();   

$(window).resize(function(){
resizeIt();
});

Now, the divs are not resizing correctly on page load or window resize. Nothing happens at all. When I include the line

$(".feature").css({"height: auto"});

In my function, the code breaks. Despite the object being present when called in the first line, it seems like there is an issue. Any insights on why this line is causing problems?

Answer №1

If you want your divs to resize dynamically when the window size changes, consider using media queries. This will eliminate the need for the page to reload every time.

@media (max-width: 1200px) {
.feature {
/*adjust height value*/
/*adjust width value*/
}
}
@media (max-width: 767px) {
.feature {
/*adjust height value*/
/*adjust width value*/
}
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error in ASP.NET MVC3: Invalid Validation Type Names

I encountered the following error message: Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required Despite my efforts, I am unable to pinpoint the root cause of this ...

Leverage the geocode callback function results from Google Maps in NodeJS to render a map on the AngularJS 2 component template

Hey there, I'm currently utilizing the Google Maps Node.js client web API and want to showcase a map on my HTML views using AngularJS 2. I have a server export that sends an object to my AngularJS2 client service const googleMapsClient = require(&ap ...

An issue encountered with getServerSideProps in NextJS 12 is causing a HttpError stating that cookies are not iterable, leading

Currently, I have an application running smoothly on my localhost. However, when it comes to production, an unexpected error has popped up: Error: HttpError: cookies is not iterable at handleError (/usr/src/.next/server/chunks/6830.js:163:11) at sendReques ...

List of descriptions: One pair per line

In need of a solution to align the term and description in a description list on the same line. The current code I have works, but it doesn't look very professional. It's time to update it with a more modern approach using flexbox. But how can I ...

How can I ensure consistency in style and components across various HTML files while allowing for unique body content?

I'm new to web development and I'm curious about the best way to create multiple pages with the same components (header, sidebar, footer) but different content. I've seen suggestions for using PHP includes and HTML imports. Let's take ...

What is the best method for changing the value of a DOM element depending on the status of another element?

Imagine implementing a text field that triggers the following code on each keydown event: if( $('#my_input').val() == '' ) $('#my_span').html('my input is blank'); else $('#my_span').html('My inpu ...

Cannot load the next page using jQuery ajax

I am working on a project with an index.html file that includes a nav menu, header, footer, and a div.content where jQuery is used to parse the html of page1.html. Initially, page1.html loads perfectly. However, I encountered an issue when trying to imple ...

Reorganizing an array using a custom prioritized list

Is it possible to sort an array but override precedence for certain words by placing them at the end using a place_last_lookup array? input_place_last_lookup = ["not","in"]; input_array = [ "good", "in", "all&qu ...

Error: The property 'classList' cannot be read as it is null in Flask, jinja2, JavaScript, HTML, and Bootstrap

I am currently utilizing a bootstrap button class, and upon clicking the button, I pass this.id to the caretToggle() JavaScript function. Since I have multiple bootstrap buttons that I want to toggle the caret on, I attempted the method below, only to enco ...

Unable to retrieve the currently focused element

I've implemented a jquery auto-resize plugin to dynamically resize my textarea. Within the plugin, I have the following code snippet: (function($){ $.fn.autoResize = function(options, idToBeShown) { updateSize = function() { // Fun ...

Guide on making a dropdown list using a JSON array within an HTML function utilizing JavaScript - instructions

With approximately fifty entries, I understand the need for an iterator to efficiently pull task after task and autofill the dropdown list. However, I'm struggling to figure out how to initiate this process. While discussing dynamically populating wit ...

Align the UL in HTML to be on the same line as other spans

When examining this jsFiddle demonstration at the following link: http://jsfiddle.net/jrXwf/1/ The UL tag showcases a star rating, with accompanying text displayed on the line below it. Is there a method to have everything appear on a single line? Appre ...

What could be causing the malfunction of the Slide Deck on my website?

I recently incorporated the HTML 5 boilerplate into my website development process. I decided to utilize both the JQuery slide deck plug-in and the JQuery pretty photo plug-in for enhanced functionality. However, I encountered an issue where placing these ...

What is causing my radio button event to activate when a separate radio button is selected?

I have implemented the code below to display "pers" and hide "bus," and vice versa. JQuery: $('input[name="perorbus"]').click(function() { if ($(this).attr('id') == 'bus') { $('#showbus&apo ...

Alert: It is not possible to update the React state on a component that is already unmounted after updating the context and switching to a different page

I am facing a challenge that requires your assistance In the /editpage, there is a changeProfile function that should be triggered upon clicking const appContext = useContext(AppContext); const [userLogin, setUserLogin] = appContext.userLogin; const [use ...

Displaying numerous images/items in a Bootstrap 2.3 carousel

I have been working on a PHP-based website that utilizes Twitter Bootstrap 2.0. Currently, I am retrieving user information from a MySQL database and attempting to display them in separate frames or items within a carousel instead of all at once using a wh ...

The schema encountered an error due to the absence of the save method

My current goal is to allow a logged in user to visit any user's URL and follow them. However, I'm encountering an issue: TypeError: Object { _id: 54bd6b90b7d4cc8c10b40cbd, name: 'Johnny', username: 'batman', __v: 0, ...

Issue with Jquery Slider Showing Empty Slide

Currently addressing issues with the slider on my site, which utilizes SlidesJS at . There seems to be a problem where it shows a blank slide inexplicably. After investigating, I noticed that a list element is being added to the pagination class, but I can ...

Connecting factors

Let me simplify what my code does: var list = { "group":{ "subgroup1":[{"name1":"Jimmy","name2":"Bob"}], "subgroup2":[{"name1":"Sarah","name2":"Nick"},{"name1":"Kevin","name2":"George"}] } } function group(group,name){ var link ...

Tips for sorting data by date in Angular 4

Seeking guidance on how to filter records in a table based on the date column. The current filtering code is generating an error message: ERROR TypeError: Cannot read property 'indexOf' of null temp = [{ "firstName":"Ravi", "date":"2019-04-0 ...