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 9189743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:18:15+00:00 2026-06-17T20:18:15+00:00

Having a problem with window resize. What I’m trying to do is check whether

  • 0

Having a problem with window resize. What I’m trying to do is check whether the window is less than 600 pixels, then prepend a div (.inner) to the body. On resize, I want to check the window width and if it’s greater than 600 pixels, put the div (inner) back in its place.

HTML

<body>
  <div class="outer">
     <div class="inner">
     </div>
  </div>

JS

var windowWidth = $(window).width();

checkWidth();

function checkWidth(){
    if(windowWidth > 600){
    $('.outer').append($('.inner'));
    console.log('back in place');
  } else {
    $('body').prepend($('.inner'));
        console.log('prepend');
  }
}
$(window).resize(function() {
  checkWidth();
}).trigger('resize');
  • 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-06-17T20:18:17+00:00Added an answer on June 17, 2026 at 8:18 pm

    You need to retrieve the width inside of your function. Otherwise it will always contain the value before the resize.

    $(checkWidth);
    $(window).resize(checkWidth).trigger('resize');
    
    function checkWidth()
    {
        var window_width = $(window).width();
    
        if(window_width > 600)
        {
            $('.outer').append($('.inner'));
            console.log('back in place');
        } 
        else 
        {
            $('body').prepend($('.inner'));
            console.log('prepend');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem getting javascript to execute whenever I resize the browser window.
The following code is having some problem with the jQuery. <script type="text/javascript"> $(window).load(function() {
I am having problem of floating the div when reducing the windows screen size.
I'm having a strange problem, that I've been trying to solve for too long.
I'm having an issue identical to this poster: Jquery problem with height() and resize()
I am having a problem redrawing a QWidget window after its size has been
I'm having a problem with making one div overlap the rest of the page.
I'm having a problem with using Supersized in a responsive website. If the window
I am having serious problems trying to resize columns in a DataGrid. I've been
I'm having a little problem with my resize event... I created a component myself,

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.