Restart following the execution of a Jquery function

I've implemented a jQuery function to expand one div when another is clicked:

    <script type="text/javascript">
    $(document).ready(function() {
        $(".flip").click(function() {
            $(".module").slideToggle("slow");
        });
    });
</script>

Here's the corresponding HTML code:

<div class="flip"></div>
        <div class="module"></div>

The module div contains a lot of text. This is the accompanying CSS:

 .module {
    width:374px;
    height:100%;
    float:left;
    padding:5px;
    display:none;
}
    .flip {
    width:100%;
    height:25px;
    background-image:url(menu.gif);
    cursor:pointer;

}

My website is responsive, so the CSS mentioned above is applied when the screen size is less than 800px. When testing, expanding and collapsing the module works perfectly. However, if I hide the content by resizing the window to below 800px and then resize it back to say 1000px, the content remains hidden even though the button for larger screens has been hidden. Is there a way to reset the jQuery effects when the browser window is resized to over 800px?

Answer №1

$(window).resize(function() {
 if($(window).width() > 800) {
  location.reload();
 }
});

Implement this code snippet to monitor window size and trigger a reload when necessary

Answer №2

Check out enquire.js, a helpful library that enhances javascript with media query callbacks.

Answer №3

One way to handle resizing events is by using the $.resize() method for checking the width dimension.

$(window).resize(function() {
    if($(window).width() > 800) {
        $(".block").show();
    }
    else{
        $(".block").hide();
    }
});

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

Is there a way to fill the remaining height of the parent with the middle item when sandwiched between two others using CSS?

I am facing a design challenge with a parent container that has 3 children arranged vertically. The top and bottom children are wide (600x200), while the middle child is tall (200x600). The parent container itself is much smaller (100x200) as I want to ens ...

What is the best way to create a line break within a loop in React?

I have a react component that I need to format into multiple lines, specifically having 2 boxes on top and 3 below in a looped return. The desired layout is to stack the boxes in 2x2 or 2x3 depending on the total number of boxes generated by the loop. So, ...

Randomly selecting JavaScript with different likelihoods or percentages

I am currently running a Node.js process with setInterval that occurs every 100ms. Within this process, I have specific actions that I want to execute at varying intervals such as 2% of the time for action X and 10% of the time for action Y. Currently, my ...

Error: Openshift's Node.js module is unable to locate the module "mosca"

We encountered an issue when trying to include mosca = require("mosca") in our server.js script. Any advice on how to resolve this error would be greatly appreciated. ^ Error: Cannot find module 'mosca/index.js' at Function.Module._ ...

Passing a variable via routes using Express

app.js var express = require('express'); var app = express(); var textVariable = "Hello World"; var homeRoute = require('./routes/index'); app.use('/', homeRoute); index.js var express = require('express'); var ...

Tips for dynamically passing a path in require method in JavaScript

I am facing an issue while trying to set require() with a dynamic path myPath: let myPath = './myDynamicModule'; require( { myPath } ) However, I keep encountering the following error: error: bundling failed: myComponent.js: myComponent.js ...

Combining two arrays using a delimiter for rows in JQuery

I have two arrays containing selectedGuids and selectedUserNames values. selectedGuids = $('.chkAllDates:checked').map(function () { return $(this).attr('Guid'); }) ...

What is the best way to condense text within a header and still maintain right-aligned buttons?

I'm having trouble using css to position some buttons on the right side of my header, while also ensuring that the text collapses if it becomes as wide as the buttons. I want to maintain justification and show ellipsis for the main text of the breadcr ...

Solid colored fill for the active item in the Bootstrap navbar

As I work on constructing a web page using Bootstrap 5 with a fixed top navbar, I am aiming to have the "active" item highlighted with a solid background color similar to the example shown here. Upon inspecting the page using developer tools, I noticed th ...

What is the best method to adjust the scrollbar to the correct position on the table?

Currently facing an issue with adding a scrollbar on the right side of my table. I have tried using a jQuery plugin called table_scroll.js but encountering difficulties. The problem can be seen in this image: https://i.sstatic.net/XqLBD.png. Any assistan ...

Converting a Perl hash into a JavaScript hash: A comprehensive guide

I am currently using the template toolkit framework and working with a Perl hash data type in my tt file. My goal is to convert this Perl hash data type into a JavaScript hash data type. Code: template: [% PERL %] use JSON qw(encode_json) ...

Is there a way to access the refScrollView.current value in a React Native application?

Working on a project with react-native I am trying to retrieve my scroll position by using a ScrollView component. However, when I execute my code and print console.log(refScrollView.current) it returns `null` How can I access the value of refScrollVie ...

The alignment of the third column div is off and not displaying properly

I am having some trouble with aligning the divs on my page in a column layout. Despite setting the first two divs to float left, the third one does not align properly. I want the third div to be floated right and aligned with the first two. You can see an ...

Guide to refining a JSON array using a pre-established list

I'm in need of assistance figuring out how to accomplish the following task: Below is the code snippet I am working with: public class Data { public string FirstName; public string LastName; public int Age; } var data = new Data { //this objec ...

Accessing the current route in a Vuex module using Vue.js

I've created a vuex store with namespaces that retrieves a specific store entry based on the current route parameter. import Router from '../../router/index' const options = { routeIdentifier: 'stepId' } export function fetchFr ...

Unseen components and columns with Bootstrap 4

I am attempting to hide a checkbox input in the middle of some column elements using Bootstrap 4. <div class="container"> <div class="row"> <a class="col-2"> 1 of 2 </a> <input type="checkbox" class="invisibl ...

What precautions can I take to safely and securely extend event handling?

I am currently developing a small JavaScript library that includes components requiring "messages" based on specific page events, which allow users to define response functions. I need to access general events like onkeydown and let users determine how eac ...

What is the correct way to include viewport width in pixels using CSS?

My div is set to a width of 50vw with padding of 25px on all sides. I am looking to add a fixed element to the right of it by increasing its width by 50vw and adding 25px. Can this be achieved using only CSS, or should I consider using Less? If so, how c ...

What could be the reason for my directive not properly interpolating the scope variable?

I attempted to create a directive that would swap out a CSS link with an inline style definition. Check out the functional version here. Now, I am hoping to achieve the same functionality using interpolation, so that I don't have to manually set the ...

JSON data is returned as Object Object

Trying to work with a JSON object and need to stringify it for localStorage: $http.post('http://localhost:8000/refresh', { name: $scope.name, email: $scope.email, token: $rootScope.devToken, platform: ionic.Platform.platform() }).then( ...