Utilizing jQuery for effective caching of jQuery Sortable elements

As someone who is relatively new to jQuery, I've been exploring and experimenting with it lately. It's not as daunting as some might think, and I'm starting to grasp it better. For instance, I created a grid that allows users to move objects around on a list using this link: http://jqueryui.com/sortable/#display-grid.

Now, my question is about caching jQuery. Below is an example of my code. I want to keep track of where a user moves items within the #sortable. So, if they, for example, move item '4' to position '8', I want the browser to remember this layout for the next page load until the cache is cleared. This will save users from having to rearrange items every time the page reloads.

I've been working on designing a fully responsive, draggable, and sortable Joomla 3.2 template. Everything works smoothly except for the caching issue. Currently, when you move module positions around, you have to repeat the process after each page reload, which can be tedious.

I considered using HTML5's LocalStorage method but unsure about how to implement it. Is there a way in jQuery to handle this? Specifically, I need to save the CSS ID #sortable indicated in the CSS below.

HTML Markup:

<!doctype html>

<html lang="en">

<head>

  <meta charset="utf-8">

  <title>Tesing</title>

  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>

  <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

  <link rel="stylesheet" href="http://blahblah.com/jQuery_Site/scripts/css/style.css">

  <script src="http://blahblah.com/jQuery_Site/scripts/javascript/sortable.js"></script>

</head;
    <body>

        <div class="container">

            <ul id="sortable">

              <li class="ui-state-default">1</li>

              <li class="ui-state-default">2</li>

              <li class="ui-state-default">3</li>

                ... (remaining list elements) ...

              <li class="ui-state-default">17</li>

              <li class="ui-state-default">18</li>

            </ul>

        </div>

    </body>

</html>
... (CSS and JS sections remain unchanged)

Answer №1

localstorage.anyname = [ x1, y1, x2, y2, ... xn, yn ]

Alternatively,

localstorage.anyname = "{ el1: [x1,y1], el2: [x2,y2], ... eln: [xn,yn] }"

Another option is to utilize a cookie: Learn more about setting/unsetting cookies with jQuery here.

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

How to locate the jQuery UI dialog box

Is there a way to precisely position the jquery UI dialog at a custom location, rather than using the predefined options like center or top? Thank you for your help in providing detailed guidance. ...

Validation is performed on the Bootstrap modal form, ensuring that the modal is only loaded after the

In order to provide a better understanding of my website's file structure, I would like to give an overview. The index.php file dynamically adds many pages to my website. Here is the code from index.php: <?php include ('pages/tillBody.php ...

Is there a way to use Jquery to determine if a parent div contains a scroll

I'm trying to find a jQuery example that checks if any parent div has a scroll bar, but I can't seem to locate a helpful one. Here is the code snippet I am working with: <div> <div class="heading"> <div class="visit ...

Applying class to a different div based on the presence of a specific ID in jQuery

I'm currently working on implementing a jQuery conditional to add a class to a specific element when another element contains a certain ID. Below is the code I have created so far: <script type="text/javascript"> $(document).ready(function() { ...

Generate a dynamic text-box and drop-down list using HTML and JavaScript

My current project involves generating dynamic text-boxes based on the selection from a drop-down list and input field. https://i.sstatic.net/CMtW9.png When a user chooses 'Option 1' from the drop-down list and enters input such as 'grass& ...

Engaging with the jQuery form submission functionality

This question may seem simple, but as I am just starting to learn and understand jQuery, I apologize in advance. Imagine you have a form like the one below: <form id="form"> <input type="text" name="abc" /> <input type="text" name="def"/&g ...

Tips for adjusting Bootstrap's sub drop-down menu to the opposite side when hovering with the mouse

I'm working on a menu that has a dropdown feature, and here is a snippet of the code: <li class="nav-item flyout"> <a href="#" class="nav-link dropdown-toggle nav_sp_clr {{#ifpage 'quicklink'}}active{{/ifpage}}">Quick Links ...

Issues with scrollspy functionality in Bootstrap 4 beta

Although similar to this question, I'm facing a different issue. The solution provided there involves manually writing JavaScript code to highlight active links on scroll, while I am trying to use the scrollspy plugin. I've reviewed various othe ...

Conceal the page's content as it moves beneath a stationary div

My issue involves a fixed div position with a margin from the top of the page. When I scroll my page, the content of my relatively positioned div (containing page content) is visible under the fixed div due to the margin from the top of the page. Despite s ...

Having trouble populating input field with data returned from ajax request

Performing an Ajax Request $.ajax({ type: "GET", url: "http://localhost/CI2/index.php/login/testfunc", data: {macro: selectedmacro}, async: false, success: function (data) { $('#tinyeditor').val(data); $(&apos ...

Struggling to properly line up the baselines of navigation list items that are styled as circular elements using CSS

I have transformed my navigation menu into a series of CSS circles with text inside. The issue I am facing is that the text spills out unevenly based on the amount of content in each circle. To address this, I used a JavaScript solution to center-align the ...

JavaScript menu that pops up

Hello everyone, I've recently created an HTML5 file that, when clicked on a specific href link, is supposed to display an image in a smooth and elegant manner. However, so far it hasn't been working for me as expected. Instead of smoothly popping ...

Conceal the content in order to determine the height of images displayed next to each

I am working on a layout where there are rows with images in the left column and text in the right column. The images have a ratio of 16:9. In case the text becomes too long, I would like to show only a portion of it with a gradient mask and provide a "Rea ...

AngularJS - Troubleshooting View Scrolling Problem with CSS

One issue I'm facing is that when the content within my view causes a scrollbar to appear, it scrolls into whitespace even though the view's overflow is hidden. I suspect it might be a CSS problem related to my positioning system. Unfortunately, ...

Find the tiniest even number out of two given inputs, ensuring that the number is even. Any ideas on how to achieve this using JavaScript or HTML?

the code is always incorrectly identifying num1 as the smaller number, even when that's not the case. Additionally, if the second input is odd and the first is even, the output should indicate this. It would also be helpful to have an output stating " ...

Steps to customize a CSS file within node_modules

Is there a way to make changes to a CSS file in the "node_modules" dependency without them being overwritten when I run npm install? I want to keep the modifications I've made to the node module files. ...

The media query targeting a specific max-width and below appears to be malfunctioning

So, I'm experiencing an issue where the browser I'm using doesn't seem to be picking up the styles I've set for a max-width of 960px and below. Can anyone provide insights into what might be causing this? Any assistance would be highly ...

jquery is throwing an error of Uncaught TypeError: Illegal invocation

attempting to load data using ajax, encountering the following error message: Uncaught TypeError: Illegal invocation. The issue appears to stem from my php file as I am unsure how to pass database values to my like.php file. using jquery JavaScript: < ...

In JavaScript, the JSON Object only stored the final result from a loop

I am currently working on an HTML Site that features 4 inputRange sliders. My goal is to store all values from these sliders in a nested JSON Object when a user clicks on a button. However, I have encountered an issue where my JavaScript code only saves th ...

Using Vue.js to create numerous modal popups

Currently, I am using Vue.JS for a research project at my workplace. My focus right now is mainly on the front-end. I have a table with several entries, and when a row is clicked, I want a modal popup window to display further details about that specific ...