Here is a helpful jQuery snippet to automatically move an element/div between div elements within a targeted container. It's useful when breaking up a page with dynamic content like repeating Ad Blocks that are predictable and, therefore, less impactful.
How to use jQuery to Insert into Random Positions
1. Select the parent element and then the specific child you want to move to a random position. In our example, the target is '.item' found in the parent div '.parent'.
2. Select the target for the div/element to be moved into a random position. In our example, the target container is '.target', and we will randomly move the '.item' previously set between the paragraphs 'p' in the target.
Example of jQuery Inserting into Random Positions
The Ad block(s) on this page use this randomised position technique. Refresh the page, and the Ad Block(s) move to a random position. Note that as this is script is 'random', elements may refresh into the same place they were in on a load or previous refresh.
Join in the Discussion