In this article, we will see how to shuffle div contents using jQuery.
In this article, we will see how to shuffle div contents using jQuery. Here the div contents are another set of divs that contain some values. So what we will do is, we will add an href and in the click event we will shuffle the entire contents of our main div. I hope you will like this.
Please see this article in my blog. BackgroundRecently, I was creating a simple online game for which I needed this. I will share the game in my next article.Using the codeThe first step you need to do is add the reference.
Can we style those divs now?
See your page now.Shuffle div contents.Now we will add an href tag to fire a click event.
Next is writing the necessary scripts.
In the preceding code we are getting the contents from the div parent to a variable maindiv and we find the children of that div and finally in a while loop we will select the divs randomly and append to our main div again.See the output now.Output
When you load the first time.
Complete Code
I hope you liked this article. Please share with me your valuable feedback and suggestions. Thanks in advance.
Frontend Developer Interview Questions and Answers