- Posts: 24
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // Define a columns array var columnsArr = []; // Loop through the question rows $('table.subquestions-list tr', thisQuestion).each(function(i) { var rowIndex = i; // Loop through the row cells $('> *', this).each(function(i){ // Assign column-specific classes $(this).addClass('column-'+i+''); $(this).attr('data-column', i); // Load the columns array if(rowIndex == 0 && i > 0) { columnsArr.push(i); } }); }); // Shuffle the columns array shuffleArray(columnsArr); // Insert the cells in the shuffled order $('table.subquestions-list tr', thisQuestion).each(function(i) { var thisRow = $(this); $(columnsArr).each(function(i){ $(thisRow).append($('[data-column="'+this+'"]', thisRow)); }); }); }); function shuffleArray(array) { for (var i = array.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; } </script>