Shifting div box alignment using jQuery

<div class="full-width">
<div class="content-inner vc_col-sm-5">
    <p>This is some text This is some text This is some text</p>
</div>
<div class="slide-show vc_col-sm-7">
    <img src="imageher.jpg" alt="big image">
</div>

I have a code snippet here that displays two div boxes side by side. However, when the window width is smaller than 859px, I want to change their position so that the image comes first before the text.

<div class="full-width">
<div class="slide-show vc_col-sm-7">
    <img src="imageher.jpg" alt="big image">
</div>
<div class="content-inner vc_col-sm-5">
    <p>This is some text This is some text This is some text</p>
</div>

How can I achieve this using jQuery?

Answer №1

Here's a simple solution: just include "float: right" in the "content-inner" when the screen size drops below 859px.

You can view the code snippet on my fiddle link https://jsfiddle.net/q2x5xsu0/

@media screen and (max-width: 859px) {
    .content-inner {
      float: right;

    }
}

Answer №2

To begin, it is important to determine the size of the window as shown below:

if ($(window).width() < 960) {
   alert('Less than 960');
}
else {
   alert('More than 960');
}

After confirming the window size, you can adjust your position accordingly.

Answer №3

Here is the code snippet in "JavaScript":

<body onload="updateDisplay()">
<div class="full-width">
<div class="content-inner vc_col-sm-5" id="smallDiv">
    <p>Some sample text Some sample text Some sample text</p>
</div>
<div class="slide-show vc_col-sm-7" id="bigDiv">
    <img src="example.jpg" alt="large image">
</div>
</body>

JavaScript function:
<script>
function updateDisplay()
{
if(window.innerWidth < 859)
{
$("#smallDiv").insertAfter("#bigDiv");
}
}
</script>

Answer №4

Explore the capabilities of the $.resize() api here: https://api.jquery.com/resize/

To determine the window size, you can utilize $(window).width();

Combining these elements results in the following code snippet:

<div class="full-width">
<div class="content-inner vc_col-sm-5">
    <p>This is some text This is some text This is some text</p>
</div>
<div class="slide-show vc_col-sm-7">
    <img src="imageher.jpg" alt="big image">
</div>

<script>
    $(window).resize(function() {
        var w = $(window).width();
        if(w < 859) {
            //make changes for small configuration
        } else {
            //make changes for large configuration
        }

    });
</script>

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

Utilizing JSON Data with Angular

Currently, I am in the process of developing an AngularJS client that communicates with a REST API running on NodeJS. To retrieve data, I make GET requests by accessing specific URLs with stock symbols appended, such as localhost:8080/stocks/aapl for Apple ...

Combining CSS percentages with pixels for layout design

Having some trouble with this layout, any assistance would be greatly appreciated. The CSS DIV I'm working with is called wrapper and has a width of 1260px: #wrapper { width: 1260px; } Inside the wrapper DIV, there are three columns named column-le ...

What is the best way to develop a script allowing users to input an email address and send them a pre-written email message?

I am currently working on a webpage where users can input the following details: 1. First Name 2. Email Address 3. Recipient's Email Address After entering this information, they will be able to send a pre-defined email message which reads ...

Printing a JSON array in Angular: A step-by-step guide

Take a look at this Stackblitz example https://stackblitz.com/edit/angular-parse-object Response format received from REST API is [{"id":123,"name":Test,"value":{"pass": true, "verified": true}}, {"id":435,"name":Test12,"value":{"pass": false, "verified" ...

Nodejs having trouble establishing a connection with mongodb

After attempting the code below to set up a new database, I can't seem to find it in my MongoDB local connection. Despite using a callback function that didn't return any errors. const mongoose = require("mongoose"); mongoose.connect(& ...

How to center a container in HTML using Bootstrap techniques

Here is the code I have been working on: <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/> <div class="span4 offset4 centered"> <div class="container overflow-hidden"> < ...

Tips for incorporating CSS 4 custom properties into Angular components

Exploring the new possibilities of CSS 4 with custom properties, my goal is to utilize them in Angular. Traditionally, custom properties are used in the following manner: <div style="--custom:red;"> <div style="background-color: var(--custom ...

Incorporating HTML into the Ajax Response

I recently encountered a strange issue with a service that returns an HTML page as the AJAX response. This page contains a form that is automatically triggered by scripts within the page, resulting in a POST request being sent when the page is rendered. My ...

Guide to Modifying the Parameter Value in JMeter's "Http Request" for a checkbox with "title" text managing the state

In the HTML code, there is a checkbox element that initially has the title "Select all rows in this table": <input type="checkbox" class="form-checkbox" title="Select all rows in this table"> Upon inspection, the title ...

Utilizing AngularJS to dynamically bind input to a value with a filter and keep it updated

I'm facing an issue with an input element linked to an object property along with a filter. Even though I update the object.field programmatically, the displayed value in the input does not change, although the correct value is reflected in the DOM In ...

Ways to isolate AngularJS files without relying on the global scope

I came across a post on Stack Overflow discussing the best practices for declaring AngularJS modules. Despite reading it, I am still unsure about the most effective way to separate and declare angularJS files for modules, controllers, services, etc. I hav ...

Display the cost within a text box following the selection of the identifier from a dropdown menu

In the first selected menu, we choose the type and then the next menu filters the MySQL database to display the department numbers. After selecting a department number from the second menu, I need to show the department price in a text field. First select ...

How to add icons to HTML select options using Angular

Looking for a way to enhance my component that displays a list of accounts with not only the account number, but also the currency represented by an icon or image of a country flag. Here is my current component setup: <select name="drpAccounts" class= ...

"Error occurs when attempting to insert indexes into a JSON array, causing the Dat

I am facing an issue with my datatable setup. I have a php array that is converted to a JSON array and populates the table successfully. However, when I try to add calculated fields to the table using PHP, it seems like Datatables is unable to read them pr ...

Tips for maintaining the particles.js interaction while ensuring it stays under other elements

I have incorporated particle.js as a background element. By adjusting the z-index, I successfully positioned it in the background. While exploring solutions on the Github issues page, I came across a suggestion involving the z-index and this code snippet: ...

How to retrieve the value of a submit button using PHP

Struggling with PHP to fetch the value of a button but encountering errors: "Notice: Undefined index: data in /storage/ssd4/271/3416271/public_html/ajaxTest.php on line 2 Notice: Undefined index: data in /storage/ssd4/271/3416271/public_html/ajaxTest.php ...

JavaScript for Dynamic Scaling Animations

I am currently working on animating an SVG button and I am trying to incorporate the transform property with a fadeout using opacity attributes in Javascript. This is how I have attempted to write the code: (Starting with opacity 0 and scale 0) (I am awa ...

"Within class methods, the reference to "this" mistakenly points to the window object instead of the class object, and the cause of this behavior eludes

I'm facing some confusion regarding why the "this" keyword inside the class methods refers to the window object instead of the class object. I am currently working in a node environment and exporting the class to be used within a React component that ...

What is the process for identifying the ActiveX control being referenced on a webpage?

After developing a web application using ASP.NET Web Forms, I encountered a challenge with a client who has strict security policies. Whenever they try to access the web page, Internet Explorer displays a message stating: Your security settings do not all ...

Center 3 elements horizontally using Flexbox, ensuring the center element is aligned properly

Is it possible to center 3 elements using flexbox on a page? The middle element should be centered on the page, while the left and right elements can vary in width. Please refer to the image below: https://i.sstatic.net/IVdz8.png I am not certain if this ...