Adding color to individual matrix drag and drop boxes | XM Community
Skip to main content
Solved

Adding color to individual matrix drag and drop boxes

  • May 15, 2022
  • 3 replies
  • 104 views

Forum|alt.badge.img+1

Hi all! I would like to to change the color of each of my individual matrix boxes, but I can't work out how to do it. I've seen another post here that achieves what I want, but using the multiple choice options - I can't work out how to change this code so that it works with the matrix drag and drop boxes.

Here is the code that I am talking about from the referenced post:
var c=["#f9f9f9","#ececec","#ececec","#dfdfdf","#dfdfdf","#d3d3d3","#d3d3d3","#c6c6c6","#c6c6c6","#b9b9b9","#acacac"];
for(var i=0;i<=11;i++){
jQuery("#"+this.questionId+" label.SingleAnswer:eq("+i+")").css("background",c[i]);
}

And here is the question format I am trying to achieve it on:
Screen Shot 2022-05-15 at 18.37.48.png
Any help is really appreciated!

Best answer by bgooldfed

Hi mb2674,
It just needs a little tweaking based on the class names.
Give this a go:
var c=["#dedede","#c2c2c2","#ababab","#808080"]; //or whatever other colours you want
for(var i=0;i<=3;i++) {
jQuery("#"+this.questionId+" ul.AnswerBucket:eq("+i+")").css("background-color",c[i]);
}
EDIT: here is a screenshot of the result
image.png

3 replies

bgooldfed
Level 4 ●●●●
Forum|alt.badge.img+25
  • Level 4 ●●●●
  • Answer
  • May 16, 2022

Hi mb2674,
It just needs a little tweaking based on the class names.
Give this a go:
var c=["#dedede","#c2c2c2","#ababab","#808080"]; //or whatever other colours you want
for(var i=0;i<=3;i++) {
jQuery("#"+this.questionId+" ul.AnswerBucket:eq("+i+")").css("background-color",c[i]);
}
EDIT: here is a screenshot of the result
image.png


Forum|alt.badge.img+1
  • Author
  • May 16, 2022

bgooldfed
Level 4 ●●●●
Forum|alt.badge.img+25
  • Level 4 ●●●●
  • May 16, 2022

No worries :) If my solution solves your problem, please accept it as the answer so other users can find it easier.