I have 28 divs, all floating to the left with a width and height of 200px with 5px margins on the right and bottom of each div. I have successfully figured out how to place other divs after other divs through jquery. I did it like that.
$( '.inner:nth-child(10)' ).after( '<div class="test">');
It works great! But what I would like to do is change the "inner" position of the div to an nth-child position based on the width of the browser, and I managed to work it out a bit.
Here is the code I'm using:
var $window = $(window); function checkWidth() { var windowsize = $window.width(); if (windowsize > 440) { $( '.inner:nth-child(10)' ).after( '<div class="test">'); } }
So, I’ll tell you how my browser displays the “internal” div after the 10th “test” div, when the browser browser width exceeds 440 pixels. Again, this works, a few. It successfully displays the "inner" div in the correct position when the browser width exceeds 440 pixels, and also does not show the div when the browser width is below 440 pixels. But the huge problem is that whenever a window is resized, a whole bunch of divs start to be created. This is very puzzling to me. Here is jsFiddle to demonstrate my problem:
http://jsfiddle.net/EUqEm/2/
You will see that at first glance it works fine, but if you resize the HTML window in jsfiddle, the creation of the heap div will begin. In fact, the div should always remain in the right place immediately after the 10th inner div. Instead, it simply creates a bunch of other divs when the window is resized.
If someone can help me solve this problem and get this little problem that will work correctly in jsfiddle, this will mean a ton for me! :)
source share