Orientation Change to calculate width of Div

I created an event listener for when I rotate my device. The event should find the width of a div box and AFTER it resizes make the width of a second Div the same. So both Div’s will have same width.

Right now my code calculates the Div width in its first state and applies that width to the second div. How do I capture the width of the Div after rotation happens.

 window.addEventListener("orientationchange", function() {
      $(".fav-bar-mobile").css({'width': ($(".tab-content").width() + 'px')});

Hi there henk3,

why don’t you just let CSS media queries do this job for you? :biggrin:

Further reading:-

MDN - Using media queries


1 Like

I am not sure how to apply this.

I understand that @media is something I add to my CSS but how do I get the width of one div and then apply it to another with this method? The first and second divs width will vary depending on the screen size

Hi there henk3

To comment, we really would need to see the problem. :winky:


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.