Move block in mobile version with jQuery / ~#root -i Move block in mobile version with jQuery / ~#root -i Move block in mobile version with jQuery / ~#root -i Move block in mobile version with jQuery / ~#root -i Move block in mobile version with jQuery / ~#root -i Move block in mobile version with jQuery / ~#root -i Move block in mobile version with jQuery / ~#root -i Move block in mobile version with jQuery / ~#root -i
  • RU
  • UA
  • EN
  • Create an online store
  • Documentation
  • Blog
    • Unix ОS
    • Php
    • MySQL
    • JavaScript
    • Package Managers
    • Docker
    • Seo
  • Auxiliary services
    • Short Links
    • Exchange views YouTube
  • Sign in
  • Create Account
  • Home
  • JavaScript
  • Move block in mobile version with jQuery

Move block in mobile version with jQuery

There are situations when there is a block on the site, which is located in the same order on the desktop version, but in the mobile version its order needs to be broken. It is not always possible to convert to flex and set it with styles. Let's analyze the js option along with jquery.

Let's say we have a list:

<ul>
<li>text</li>
<li id="cut" style="color:red">Это нужно перенести в под обозначенные тег в мобильной версии</li>
<li>text</li>
<li>text</li>
<li>text</li>
<li id="insert" style="color:green">Переместить под этот тег</li>
<li>text</li>
</ul>

Список до перемещения в мобильной версии

The code that moves the desired block depending on the screen size of the device:

$(window).on('load resize', function(){
if ($(window).width() < 768) {
$('#cut').insertAfter('#insert');
}
});

load resize - when loading or changing the screen size

width() < 768 - screen size at which this works

insertAfter() - insert tag id="cut" after id="insert"

This code will only work on the mobile version of the site. On the desktop version, the user will not see this.

02 February 20
1115
0

Comments

wlad2.ru

11 January 2022 11:27
Чтобы убрать ошибку Uncaught TypeError: $ is not a function
правильный код вот

$(window).on('load resize', function(){
if ($(window).width() < 768) {
$('#cut_col-sm-12').insertAfter('#insert_cut_col-sm-12');
}
});
2
Name
E-mail
Rating
Review

Other articles from the category

01 April 2021

In input only numbers on js

A simple JS script, filtering input information in input. Enter only numbers.

29 January 2019

Gulp Error watch path ENOSPC in gaze.js or grunt.js

Let's consider a possible solution to the problem when running Gulp on Ubuntu 18.04 with an error Error: watch /path/ ENOSPC. Let's analyze what the max_user_watches parameters are.

21 May 2018

Code highlighting on the site using Js and Css

When describing minimal codes that have a syntax similar to C++, it may be necessary to have minimal highlighting on the site for better readability. I will give the easiest way to highlight, which I took from habrahabr. Consider, connect, describe ...

Categories

  • Unix OS
  • Php
  • MySQL
  • JavaScript
  • Package Managers
  • Docker
  • Seo

Latest comments

Добрый день, Сергей. Я на более новых версиях блют...
root-i
23.02.23
Пробовал на transmart колонке. Ничего из перечисле...
Сергей
20.02.23
HenryMit, может быть
root-i
07.02.23
Неофрейдизм — это… Определение, принципы, представ...
HenryMit
07.02.23

I share information in which I needed help and spent a lot of time figuring it out. If the information helped at least one person, then this site was not created in vain.

Thank you for the continuation of the site:
Contacts

Telegram Viber Mail

Search for articles

  • Sign in
  • Create Account

Powered by chmod -R